diff --git a/.prettierrc b/.prettierrc
new file mode 100644
index 0000000..9e26dfe
--- /dev/null
+++ b/.prettierrc
@@ -0,0 +1 @@
+{}
\ No newline at end of file
diff --git a/package.json b/package.json
index 8abf1d7..9a9402f 100644
--- a/package.json
+++ b/package.json
@@ -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",
diff --git a/pages/api/index.js b/pages/api/index.js
new file mode 100644
index 0000000..86edc2d
--- /dev/null
+++ b/pages/api/index.js
@@ -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;
\ No newline at end of file
diff --git a/pages/api/note/[id].js b/pages/api/note/[id].js
index 5f3c7b9..8ac147d 100644
--- a/pages/api/note/[id].js
+++ b/pages/api/note/[id].js
@@ -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)
@@ -48,3 +88,4 @@ const handler = nc()
export default handler
+>>>>>>> master
diff --git a/pages/api/note/index.js b/pages/api/note/index.js
index 3a6935b..3d3e784 100644
--- a/pages/api/note/index.js
+++ b/pages/api/note/index.js
@@ -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()
@@ -15,3 +33,4 @@ const handler = nc()
export default handler
+>>>>>>> master
diff --git a/pages/index.jsx b/pages/index.jsx
index f118684..6e85dd0 100644
--- a/pages/index.jsx
+++ b/pages/index.jsx
@@ -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 }) => (
+
+);
+
+export function getStaticProps() {
+ //GET DATA FROM CMS
+
+ return {
+ props: {
+ content: {
+ title: "I don't get this actually.",
+ },
+ },
+ };
+=======
export default ({content}) => (
@@ -19,4 +46,5 @@ export async function getStaticProps() {
}
}
}
+>>>>>>> master
}
diff --git a/pages/notes/[id].jsx b/pages/notes/[id].jsx
index 8a3f0db..e83d10a 100644
--- a/pages/notes/[id].jsx
+++ b/pages/notes/[id].jsx
@@ -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 (
-
+
Note: {id}
- )
+ );
+};
+
+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
diff --git a/pages/notes/index.jsx b/pages/notes/index.jsx
index 9412e69..2a89ab6 100644
--- a/pages/notes/index.jsx
+++ b/pages/notes/index.jsx
@@ -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 (
-
+
My Notes
-
- {notes.map(note => (
-
+
+ {notes.map((note) => (
+
- )
+ );
+};
+
+export async function getServerSideProps() {
+ const res = await fetch("http://localhost:3000/api/note");
+
+ const { data } = await res.json();
+ return {
+ props: { notes: data },
+ };
}
diff --git a/src/data/data.js b/src/data/data.js
index 9f28cc1..8ed02f6 100644
--- a/src/data/data.js
+++ b/src/data/data.js
@@ -1,4 +1,13 @@
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,
@@ -6,3 +15,4 @@ const notes = new Array(15)
}))
module.exports = notes
+>>>>>>> master
diff --git a/yarn.lock b/yarn.lock
index c97f1de..1e0357a 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -4130,6 +4130,14 @@ 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"
@@ -4137,6 +4145,7 @@ next-connect@^0.8.1:
dependencies:
"@types/node" "^14.0.14"
trouter "^3.1.0"
+>>>>>>> master
next-env@^1.1.1:
version "1.1.1"
@@ -5876,10 +5885,17 @@ traverse@0.6.6:
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"