Skip to content

Commit d7d608f

Browse files
committed
Add key to fix hydration, which then needed replacing <></> with real tags.
Add TypeScript interfaces to replace 'any'.
1 parent 0fdf13d commit d7d608f

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

pages/lessons/index.tsx

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
1-
import { Flex, Stack, Heading } from '@chakra-ui/react'
1+
import { Flex, Stack, Heading, Box } from '@chakra-ui/react'
22
import fs from 'fs'
33
import path from 'path'
44
import matter from 'gray-matter'
55
import { ContentBanner } from '../../components/ContentBanner'
66

7+
interface Lesson {
8+
path: string
9+
frontMatter: any
10+
slug: string
11+
}
12+
713
interface LessonProps {
8-
lessons: {
9-
path: string
10-
frontMatter: any
11-
slug: string
12-
}[]
14+
lessons: Lesson[]
1315
}
1416

15-
const Lessons: React.FC<LessonProps> = ({ lessons }) => {
16-
const result = lessons.reduce((acc: any, curr: any) => {
17-
if (!acc[curr.path]) acc[curr.path] = []
17+
interface LessonTrackMap {
18+
[key: string]: Lesson[]
19+
}
1820

21+
const Lessons: React.FC<LessonProps> = ({ lessons }: { lessons: Lesson[] }) => {
22+
const result = lessons.reduce((acc: LessonTrackMap, curr) => {
23+
if (!acc[curr.path]) {
24+
// initial an array of lessons for a given track
25+
acc[curr.path] = []
26+
}
1927
acc[curr.path].push(curr)
2028
return acc
2129
}, {})
@@ -25,16 +33,22 @@ const Lessons: React.FC<LessonProps> = ({ lessons }) => {
2533
<Flex as="main" py={5} px={[4, 10, 16]} direction="column" minH="90vh">
2634
<Stack spacing={5} direction="column">
2735
<>
28-
{Object.entries(result).map((track: any) => {
36+
{Object.entries(result).map((track, idx: number) => {
37+
const trackName = track[0].toUpperCase()
38+
const lessons = track[1]
2939
return (
30-
<>
40+
<Box key={idx}>
3141
<Heading size="lg" color="yellow.300">
32-
{track[0].toUpperCase()}
42+
{trackName}
3343
</Heading>
34-
{track[1].map((lesson: any, idx: number) => {
35-
return <ContentBanner key={idx} lesson={lesson} idx={idx} />
44+
{lessons.map((lesson: Lesson, idx: number) => {
45+
return (
46+
<Box marginTop="4" key={idx}>
47+
<ContentBanner lesson={lesson} idx={idx} />
48+
</Box>
49+
)
3650
})}
37-
</>
51+
</Box>
3852
)
3953
})}
4054
</>
@@ -48,7 +62,7 @@ export default Lessons
4862

4963
export const getStaticProps = async () => {
5064
const directories = fs.readdirSync(path.join('lessons'))
51-
const lessons: object[] = []
65+
const lessons: Lesson[] = []
5266
directories.reverse().map((filename) => {
5367
fs.readdirSync(path.join('lessons', filename)).map((file) => {
5468
const markdownWithMeta = fs.readFileSync(

0 commit comments

Comments
 (0)