|
| 1 | +import React from 'react' |
| 2 | +import { PageLayout } from './PageLayout' |
| 3 | +import { Drawing } from '../types' |
| 4 | +import { DrawingTile } from './DrawingTile' |
| 5 | +import Link from 'next/link' |
| 6 | +import styled from 'styled-components' |
| 7 | +import { getPreviousDay, getNextDay } from '../lib/drawings' |
| 8 | +import { useRouter } from 'next/router' |
| 9 | +import Div100vh from 'react-div-100vh' |
| 10 | + |
| 11 | +export const DayPage: React.FC<{ drawings: Drawing[], day: string }> = ({ drawings, day }) => { |
| 12 | + const year = parseInt(day.slice(0, 4), 10) |
| 13 | + const router = useRouter() |
| 14 | + const goToPrevious = () => router.push(`/day/${getPreviousDay(day)}`) |
| 15 | + const goToNext = () => router.push(`/day/${getNextDay(day)}`) |
| 16 | + |
| 17 | + const onKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => { |
| 18 | + const handler = ({ |
| 19 | + ArrowUp: goToPrevious, |
| 20 | + ArrowDown: goToNext, |
| 21 | + ArrowLeft: goToPrevious, |
| 22 | + ArrowRight: goToNext, |
| 23 | + } as Record<string, Function>)[event.key] |
| 24 | + handler?.() |
| 25 | + } |
| 26 | + |
| 27 | + return ( |
| 28 | + <PageLayout title={`explodingdog ${day}`} showHeader={false} showFooter={false}> |
| 29 | + <Div100vh> |
| 30 | + <Container onKeyDown={onKeyDown} tabIndex={-1}> |
| 31 | + <DayHeading>{day}</DayHeading> |
| 32 | + <DrawingSection> |
| 33 | + {drawings && drawings.map(drawing => ( |
| 34 | + <DrawingTile key={`${drawing.date} ${drawing.slug}`} {...drawing} /> |
| 35 | + ))} |
| 36 | + </DrawingSection> |
| 37 | + <NavBar> |
| 38 | + <Link href="/day/[id]" as={`/day/${getPreviousDay(day)}`}> |
| 39 | + <Arrow><</Arrow> |
| 40 | + </Link> |
| 41 | + <Link href="/"><a>{'Home'}</a></Link> |
| 42 | + <Link href="/year/[id]" as={`/year/${year}`}> |
| 43 | + <YearLink>{year}</YearLink> |
| 44 | + </Link> |
| 45 | + <Link href="/day/[id]" as={`/day/${getNextDay(day)}`}> |
| 46 | + <Arrow>></Arrow> |
| 47 | + </Link> |
| 48 | + </NavBar> |
| 49 | + </Container> |
| 50 | + </Div100vh> |
| 51 | + </PageLayout> |
| 52 | + ) |
| 53 | +} |
| 54 | + |
| 55 | +const Container = styled.main.attrs({ className: 'Explorer__DrawingPage__Container'})` |
| 56 | + display: flex; |
| 57 | + flex-direction: column; |
| 58 | + justify-content: space-between; |
| 59 | + height: 100%; |
| 60 | + max-height: 100%; |
| 61 | +` |
| 62 | + |
| 63 | +const DayHeading = styled.h1.attrs({ className: 'Explorer__DayPage__DayHeading'})` |
| 64 | + font-size: 32px; |
| 65 | + padding: 12px 16px; |
| 66 | + text-align: center; |
| 67 | +` |
| 68 | + |
| 69 | +const DrawingSection = styled.section.attrs({ className: 'Explorer__DayPage__DrawingSection'})` |
| 70 | + overflow: scroll; |
| 71 | + text-align: center; |
| 72 | +` |
| 73 | + |
| 74 | +const NavBar = styled.nav.attrs({ className: 'Explorer__DrawingPage__Header'})` |
| 75 | + color: #BBB; |
| 76 | + display: flex; |
| 77 | + justify-content: space-between; |
| 78 | + font-size: 18px; |
| 79 | + font-weight: bold; |
| 80 | + height: 80px; |
| 81 | + line-height: 80px; |
| 82 | +` |
| 83 | + |
| 84 | +const Arrow = styled.div.attrs({ className: 'Explorer__DrawingPage__Arrow'})` |
| 85 | + color: black; |
| 86 | + cursor: pointer; |
| 87 | + font-size: 36px; |
| 88 | + line-height: 74px; |
| 89 | + padding: 0 5%; |
| 90 | + user-select: none; |
| 91 | +
|
| 92 | + &:hover { |
| 93 | + background: #f8f8f8; |
| 94 | + } |
| 95 | +` |
| 96 | + |
| 97 | +const YearLink = styled.a.attrs({ className: 'Explorer__DrawingPage__YearLink'})` |
| 98 | + cursor: pointer; |
| 99 | +` |
0 commit comments