Skip to content

Commit cecc6e5

Browse files
committed
chore
1 parent 8cfbc1f commit cecc6e5

File tree

4 files changed

+52
-7
lines changed

4 files changed

+52
-7
lines changed

pages/index.jsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,21 @@
22
import { jsx } from 'theme-ui'
33
import Link from 'next/link'
44

5-
export default () => (
5+
export default ({content}) => (
66
<div sx={{ height: `calc(100vh - 60px)`}}>
77
<div sx={{variant: 'containers.page', display: 'flex', alignItems: 'center', height: '100%'}}>
8-
<h1 sx={{fontSize: 8, my: 0}}>This is a really dope note taking app.</h1>
8+
<h1 sx={{fontSize: 8, my: 0}}>{content.title}</h1>
99
</div>
1010
</div>
1111
)
12+
13+
14+
export async function getStaticProps() {
15+
return {
16+
props: {
17+
content: {
18+
title: 'Look at my note app tho'
19+
}
20+
}
21+
}
22+
}

pages/notes/[id].jsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { jsx } from 'theme-ui'
33
import { useRouter } from 'next/router'
44
import Link from 'next/link'
55

6-
export default () => {
6+
const Note = () => {
77
const router = useRouter()
88
const { id }= router.query
99

@@ -13,3 +13,24 @@ export default () => {
1313
</div>
1414
)
1515
}
16+
17+
export default Note
18+
19+
export async function getServerSideProps({params, req, res}) {
20+
const response = await fetch(`http://localhost:3000/api/note/${params.id}`)
21+
22+
if (!response.ok) {
23+
res.writeHead(302, { Location: '/notes' })
24+
res.end()
25+
return {props: {}}
26+
}
27+
28+
const {data} = await response.json()
29+
30+
31+
if (data) {
32+
return {
33+
props: {note: data}
34+
}
35+
}
36+
}

pages/notes/index.jsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
import { jsx } from 'theme-ui'
33
import Link from 'next/link'
44

5-
export default () => {
6-
const notes = new Array(15).fill(1).map((e, i) => ({id: i, title: `This is my note ${i}`}))
7-
5+
export default ({notes}) => {
86
return (
97
<div sx={{variant: 'containers.page'}}>
108
<h1>My Notes</h1>
@@ -25,3 +23,13 @@ export default () => {
2523
</div>
2624
)
2725
}
26+
27+
28+
export async function getServerSideProps() {
29+
const res = await fetch(`http://localhost:3000/api/note`)
30+
const {data} = await res.json()
31+
32+
return {
33+
props: {notes: data}
34+
}
35+
}

src/data/data.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
const notes = []
1+
const notes = new Array(15)
2+
.fill(1)
3+
.map((_, i) => ({
4+
id: Date.now() + i,
5+
title: `Note ${i}`
6+
}))
27

38
module.exports = notes

0 commit comments

Comments
 (0)