Skip to content
This repository has been archived by the owner on Jul 29, 2022. It is now read-only.

Commit

Permalink
Flexbox playing around
Browse files Browse the repository at this point in the history
  • Loading branch information
phocks committed Nov 21, 2019
1 parent d135129 commit f7cc257
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 8 deletions.
2 changes: 1 addition & 1 deletion components/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

.container {
min-height: 100%;
padding-top: 32px;
}

:global {
html {
height: 100%;
overflow: hidden;
}
body {
margin: 0;
Expand Down
1 change: 0 additions & 1 deletion components/title.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
justify-content: center;
margin-left: 16px;
margin-right: 16px;
margin-top: 32px;
}

.title {
Expand Down
10 changes: 10 additions & 0 deletions lib/mongodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,15 @@ export const findOne = async (collection, query) => {
const result = await col.findOne(query);
client.close();

return result;
}

export const findMany = async (collection, query) => {
const client = await MongoClient.connect(url, options);
const db = client.db(dbName);
const col = db.collection(collection);
const result = await col.find(query).toArray();
client.close();

return result;
}
3 changes: 2 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = withSass({
cssModules: true,
cssLoaderOptions: {
importLoaders: 1,
localIdentName: "[local]___[hash:base64:5]"
localIdentName: "[local]___[hash:base64:5]",
camelCase: true
}
});
3 changes: 1 addition & 2 deletions pages/api/get-quotes/[username].js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MongoClient } from "mongodb";
import { dbName, url, options } from "../../../lib/mongodb";

const main = async (req, res) => {
export default async (req, res) => {
const { username } = req.query;

const client = await MongoClient.connect(url, options);
Expand All @@ -19,4 +19,3 @@ const main = async (req, res) => {
}
};

export default main;
6 changes: 6 additions & 0 deletions pages/api/get-quotes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { findMany } from "../../../lib/mongodb";

export default async (req, res) => {
const quotes = await findMany("quotations", {})
res.json(quotes)
};
19 changes: 16 additions & 3 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,37 @@ const Home = props => {
const setTitle = useStoreActions(actions => actions.setTitle);
setTitle("Quoke");

const { quotes } = props;

return (
<div className={css.root}>
<Title text="/quoke" />
<Quotation quote={props.randomQuote} />
<hr />

{/* <Info quote={props.randomQuote} /> */}
{/* <div className={css.quotesRoot}>
<div className={css.quotesContainer}>
{quotes &&
quotes.map((quote, index) => <div key={index} className={css.quoteTeaser}>{quote.text}</div>)}
</div>
</div> */}
</div>
);
};

Home.getInitialProps = async ({ req, query }) => {
const { origin } = absoluteUrl(req);

const fetched = await fetch(origin + "/api/random");
const data = await fetched.json();
let fetched = await fetch(origin + "/api/random");
const randomQuote = await fetched.json();

fetched = await fetch(origin + "/api/get-quotes");
const quotes = await fetched.json();

return {
randomQuote: data
randomQuote: randomQuote,
quotes: quotes
};
};

Expand Down
21 changes: 21 additions & 0 deletions pages/index.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
.root {

}

.quotes-root {
font-size: 14px;
display: flex;
justify-content: center;
margin-left: 16px;
margin-right: 16px;

}

.quotes-container {
max-width: 590px;
width: 100%;
}

.quote-teaser {
margin-bottom: 24px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}

1 comment on commit f7cc257

@vercel
Copy link

@vercel vercel bot commented on f7cc257 Nov 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.