Skip to content
Open

Main #17

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
"body-parser": "^1.19.0",
"dotenv-load": "^2.0.0",
"next": "^9.5.0",
<<<<<<< HEAD
"next-connect": "^0.12.2",
=======
"next-connect": "^0.8.1",
>>>>>>> master
"next-env": "^1.1.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
Expand Down
10 changes: 10 additions & 0 deletions pages/api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import nc from 'next-connect'

const handler = nc()
.get( async(req , res) => {
res.json({message: 'OK'})
})
.post(() => {
res.json({message: 'POSTED'})
})
export default handler;
41 changes: 41 additions & 0 deletions pages/api/note/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,46 @@ import notes from '../../../src/data/data'
const getNote = id => notes.find(n => n.id === parseInt(id))

const handler = nc()
<<<<<<< HEAD
.get((req, res) => {
const note = getNote(req.query.id)

if(!note) {
res.status(404)
res.end()
return
}
res.json({data: note})
})
.patch((req, res) => {
const note = getNote(req.query.id)

if(!note) {
res.status(404)
res.end()
return
}
const i = notes.findIndex(n => n.id === parseInt(req.query.id))
const updated = {...note , ...req.body}

notes[i] = updated
res.json({date: updated})
})
.delete((req, res) => {
const note = getNote(req.query.id)

if(!note) {
res.statusCode(404)
res.end()
return
}
const i = notes.findIndex(n => n.id === parseInt(req.body.id))

notes.splice(i, 1)
res.json({data: req.query.id})
})
export default handler;
=======
.get((req, res) => {

const note = getNote(req.query.id)
Expand Down Expand Up @@ -48,3 +88,4 @@ const handler = nc()


export default handler
>>>>>>> master
19 changes: 19 additions & 0 deletions pages/api/note/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
import nc from 'next-connect'
<<<<<<< HEAD
import notes from '../../../src/data/data';

const handler = nc()
.post((req, res) => {
const note = {
...req.body,
id: Date.now()
}
notes.push(note)
res.json({data: note})
})
.get((req, res) => {
res.json({data: notes})
})

export default handler;
=======
import notes from '../../../src/data/data'

const handler = nc()
Expand All @@ -15,3 +33,4 @@ const handler = nc()


export default handler
>>>>>>> master
32 changes: 30 additions & 2 deletions pages/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
/** @jsx jsx */
import { jsx } from 'theme-ui'
import Link from 'next/link'
import { jsx } from "theme-ui";
import Link from "next/link";

<<<<<<< HEAD
export default ({ content }) => (
<div sx={{ height: `calc(100vh - 60px)` }}>
<div
sx={{
variant: "containers.page",
display: "flex",
alignItems: "center",
height: "100%",
}}
>
<h1 sx={{ fontSize: 8, my: 0 }}>{content.title}</h1>
</div>
</div>
);

export function getStaticProps() {
//GET DATA FROM CMS

return {
props: {
content: {
title: "I don't get this actually.",
},
},
};
=======
export default ({content}) => (
<div sx={{ height: `calc(100vh - 60px)`}}>
<div sx={{variant: 'containers.page', display: 'flex', alignItems: 'center', height: '100%'}}>
Expand All @@ -19,4 +46,5 @@ export async function getStaticProps() {
}
}
}
>>>>>>> master
}
34 changes: 29 additions & 5 deletions pages/notes/[id].jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,41 @@
/** @jsx jsx */
import { jsx } from 'theme-ui'
import { useRouter } from 'next/router'
import Link from 'next/link'
import { jsx } from "theme-ui";
import { useRouter } from "next/router";
import Link from "next/link";

<<<<<<< HEAD
export default () => {
const router = useRouter();
const { id } = router.query;
=======
const Note = () => {
const router = useRouter()
const { id }= router.query
>>>>>>> master

return (
<div sx={{variant: 'containers.page'}}>
<div sx={{ variant: "containers.page" }}>
<h1>Note: {id} </h1>
</div>
)
);
};

export async function getServerSideProps({ params, req, res }) {
const response = await fetch(`http://localhost:3000/api/note/${params.id}`);
if (!response.ok) {
res.writeHead(301, {
Location: "/notes",
});
res.end();
return {
props: {},
};
}
const { data } = await response.json();

return {
props: { note: data },
};
}

export default Note
Expand Down
37 changes: 30 additions & 7 deletions pages/notes/index.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
/** @jsx jsx */
<<<<<<< HEAD
import { jsx } from "theme-ui";
import Link from "next/link";

export default ({ notes }) => {
=======
import { jsx } from 'theme-ui'
import Link from 'next/link'

export default ({notes}) => {
>>>>>>> master
return (
<div sx={{variant: 'containers.page'}}>
<div sx={{ variant: "containers.page" }}>
<h1>My Notes</h1>

<div sx={{display: 'flex', justifyContent: 'space-between', alignItems: 'center', flexWrap: 'wrap'}}>
{notes.map(note => (
<div sx={{width: '33%', p: 2}} key={note.id}>
<div
sx={{
display: "flex",
justifyContent: "space-between",
alignItems: "center",
flexWrap: "wrap",
}}
>
{notes.map((note) => (
<div sx={{ width: "33%", p: 2 }} key={note.id}>
<Link href="/notes/[id]" as={`/notes/${note.id}`}>
<a sx={{textDecoration: 'none', cursor: 'pointer'}}>
<div sx={{variant: 'containers.card',}}>
<a sx={{ textDecoration: "none", cursor: "pointer" }}>
<div sx={{ variant: "containers.card" }}>
<strong>{note.title}</strong>
</div>
</a>
Expand All @@ -21,7 +35,16 @@ export default ({notes}) => {
))}
</div>
</div>
)
);
};

export async function getServerSideProps() {
const res = await fetch("http://localhost:3000/api/note");

const { data } = await res.json();
return {
props: { notes: data },
};
}


Expand Down
10 changes: 10 additions & 0 deletions src/data/data.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
const notes = new Array(15)
<<<<<<< HEAD
.fill(1)
.map((_, i) => ({
id: Date.now()+i,
title: `Note ${i}`
}))

module.exports = notes
=======
.fill(1)
.map((_, i) => ({
id: Date.now() + i,
title: `Note ${i}`
}))

module.exports = notes
>>>>>>> master
16 changes: 16 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4130,13 +4130,22 @@ neo-async@^2.5.0, neo-async@^2.6.1:
resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f"
integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==

<<<<<<< HEAD
next-connect@^0.12.2:
version "0.12.2"
resolved "https://registry.yarnpkg.com/next-connect/-/next-connect-0.12.2.tgz#8191db0f03c80f8f4dbbe80e643a48cb3c9a20b9"
integrity sha512-B/zKHPs5S7XWvAVsZVLvOeY2eL2U3g0W/BgCDetEJRcNDzxX2vi8rzqBuEoLLPlI8LvtHwujDVUFFjSgOEZTbA==
dependencies:
trouter "^3.2.0"
=======
next-connect@^0.8.1:
version "0.8.1"
resolved "https://registry.yarnpkg.com/next-connect/-/next-connect-0.8.1.tgz#def20d9045fb8043855a92a3bae40d88ef3f9d3b"
integrity sha512-V5O45OV6+neCb/iXfPUpfcFirSJ4czr02+Xay7TyW/8Ybq9KzDLPWpU36lkvPbwNhpdxRXAi/j907c8MIURMww==
dependencies:
"@types/node" "^14.0.14"
trouter "^3.1.0"
>>>>>>> master

next-env@^1.1.1:
version "1.1.1"
Expand Down Expand Up @@ -5876,10 +5885,17 @@ [email protected]:
resolved "https://registry.yarnpkg.com/traverse/-/traverse-0.6.6.tgz#cbdf560fd7b9af632502fed40f918c157ea97137"
integrity sha1-y99WD9e5r2MlAv7UD5GMFX6pcTc=

<<<<<<< HEAD
trouter@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/trouter/-/trouter-3.2.0.tgz#a9c510fce21b8e659a28732c9de9d82871efe8df"
integrity sha512-rLLXbhTObLy2MBVjLC+jTnoIKw99n0GuJs9ov10J870vDw5qhTurPzsDrudNtBf5w/CZ9ctZy2p2IMmhGcel2w==
=======
trouter@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/trouter/-/trouter-3.1.0.tgz#76f4faea81d5ebd11bba4762c664a3b55eda9b23"
integrity sha512-3Swwu638QQWOefHLss9cdyLi5/9BKYmXZEXpH0KOFfB9YZwUAwHbDAcoYxaHfqAeFvbi/LqAK7rGkhCr1v1BJA==
>>>>>>> master
dependencies:
regexparam "^1.3.0"

Expand Down