Skip to content

Commit b4eb352

Browse files
committed
simplify YearPage and DayPage props, they get their own drawings
1 parent 6ccd489 commit b4eb352

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

explorer/components/DayPage.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import React from 'react'
22
import { PageLayout } from './PageLayout'
3-
import { Drawing } from '../types'
43
import { DrawingTile } from './DrawingTile'
54
import Link from 'next/link'
65
import styled from 'styled-components'
76
import { getPreviousDay, getNextDay } from '../lib/drawings'
87
import { useRouter } from 'next/router'
98
import Div100vh from 'react-div-100vh'
9+
import { dayDrawingSets } from '../__fixtures__/drawings'
1010

11-
export const DayPage: React.FC<{ drawings: Drawing[], day: string }> = ({ drawings, day }) => {
12-
const year = parseInt(day.slice(0, 4), 10)
11+
export const DayPage: React.FC<{ day: string }> = ({ day }) => {
12+
const drawings = dayDrawingSets[day]
13+
const year = drawings[0].year
1314
const router = useRouter()
1415
const goToPrevious = () => router.push(`/day/${getPreviousDay(day)}`)
1516
const goToNext = () => router.push(`/day/${getNextDay(day)}`)

explorer/components/YearPage.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import { PageLayout } from './PageLayout'
33
import { DrawingTile } from './DrawingTile'
44
import styled from 'styled-components'
55
import { YearBar } from './YearBar'
6+
import { yearDrawingSets } from '../__fixtures__/drawings'
67

7-
export const YearPage: React.FC<{ drawings: Drawing[], year: number }> = ({ drawings, year }) => {
8+
export const YearPage: React.FC<{ year: number }> = ({ year }) => {
9+
const drawings = yearDrawingSets[year]
810
return (
911
<PageLayout title={`explodingdog ${year}`}>
1012
<YearBar activeYear={year} />

explorer/pages/day/[id].tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { DayPage } from '../../components/DayPage'
22
import { GetStaticProps, GetStaticPaths } from 'next'
3-
import { dayDrawingSets, drawingDays } from '../../__fixtures__/drawings'
3+
import { drawingDays } from '../../__fixtures__/drawings'
44
import { singleQueryParamValue } from '../../lib/next'
55

66
export default DayPage
77

88
export const getStaticPaths: GetStaticPaths = async () => {
9-
const paths = drawingDays.map(day => ({ params: { id: day.toString() }}))
9+
const paths = drawingDays.map(day => ({ params: { id: day }}))
1010
return { paths, fallback: false }
1111
}
1212

1313
export const getStaticProps: GetStaticProps = async ({ params }) => {
1414
const day = singleQueryParamValue(params?.id)
15-
return { props: { day, drawings: dayDrawingSets[day] } }
15+
return { props: { day } }
1616
}

explorer/pages/year/[id].tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { YearPage } from '../../components/YearPage'
22
import { GetStaticProps, GetStaticPaths } from 'next'
3-
import { drawingYears, yearDrawingSets } from '../../__fixtures__/drawings'
3+
import { drawingYears } from '../../__fixtures__/drawings'
44

55
export default YearPage
66

77
export const getStaticPaths: GetStaticPaths = async () => {
8-
const paths = drawingYears.map(year => ({ params: { id: year.toString() }}))
8+
const paths = drawingYears.map(year => ({ params: { id: `${year}` }}))
99
return { paths, fallback: false }
1010
}
1111

1212
export const getStaticProps: GetStaticProps = async ({ params }) => {
1313
const year = Number(params?.id)
14-
return { props: { year, drawings: yearDrawingSets[year] } }
14+
return { props: { year } }
1515
}

0 commit comments

Comments
 (0)