From b1063930964bb2c90d688359d8b426a83fd9251b Mon Sep 17 00:00:00 2001 From: Szepesi Tibor Date: Thu, 11 Jan 2024 20:19:48 +0100 Subject: [PATCH] Add canteen page --- src/app.tsx | 4 +++ src/data/canteen.data.ts | 56 +++++++++++++++++++++++++++++ src/models/canteen.ts | 11 ++++++ src/pages/Canteen.module.scss | 44 +++++++++++++++++++++++ src/pages/Canteen.tsx | 68 +++++++++++++++++++++++++++++++++++ 5 files changed, 183 insertions(+) create mode 100644 src/data/canteen.data.ts create mode 100644 src/models/canteen.ts create mode 100644 src/pages/Canteen.module.scss create mode 100644 src/pages/Canteen.tsx diff --git a/src/app.tsx b/src/app.tsx index 8988de4..168ae6e 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -46,6 +46,10 @@ const ROUTES: RouteDefinition[] = [ }, ], }, + { + path: '/canteen', + component: lazy(() => import('~/pages/Canteen')), + }, { path: '/_debug', component: lazy(() => import('~/pages/Debug')), diff --git a/src/data/canteen.data.ts b/src/data/canteen.data.ts new file mode 100644 index 0000000..e6598a1 --- /dev/null +++ b/src/data/canteen.data.ts @@ -0,0 +1,56 @@ +import { gql, request } from '@solid-primitives/graphql' +import { cache } from '@solidjs/router' +import { addWeeks, getISOWeek, getISOWeekYear } from 'date-fns' +import { GRAPHQL_BACKEND_URL } from '~/constants' +import { Day } from '~/models/canteen' + +const QUERY = gql` + query CanteenTwoWeeks($year1: Int!, $week1: Int!, $year2: Int!, $week2: Int!) { + week1: canteen(year: $year1, week: $week1) { + ...canteen + } + week2: canteen(year: $year2, week: $week2) { + ...canteen + } + } + + fragment canteen on Canteen { + date + menus { + menu + type + } + } +` + +export type CanteenData = [Day[], Day[]] + +export const queryCanteen = cache(async (): Promise => { + const now = new Date() + const nextWeek = addWeeks(now, 1) + + type Result = { + week1: Day[] + week2: Day[] + } + + const response = await request(GRAPHQL_BACKEND_URL, QUERY, { + variables: { + year1: getISOWeekYear(now), + week1: getISOWeek(now), + year2: getISOWeekYear(nextWeek), + week2: getISOWeek(nextWeek), + }, + }) + + return [ + response.week1.map((d) => ({ + ...d, + date: new Date(d.date), + })), + response.week2.map((d) => ({ + ...d, + date: new Date(d.date), + })), + ] +}, 'Canteen.queryCanteen') diff --git a/src/models/canteen.ts b/src/models/canteen.ts new file mode 100644 index 0000000..ab1ec16 --- /dev/null +++ b/src/models/canteen.ts @@ -0,0 +1,11 @@ +export type Day = { + id: number + menus: [Menu, Menu, Menu?] + date: D +} + +export type Menu = { + id: number + menu: string + type: number +} diff --git a/src/pages/Canteen.module.scss b/src/pages/Canteen.module.scss new file mode 100644 index 0000000..b58c440 --- /dev/null +++ b/src/pages/Canteen.module.scss @@ -0,0 +1,44 @@ +.container { + max-width: var(--content-page-width); + padding-inline: var(--page-padding); + margin-inline: auto; + + h1, h2 { + text-align: center; + font-weight: 700; + } +} + +.columns { + display: grid; + grid-gap: 2rem; + + @include lg { + grid-template-columns: 1fr 1fr; + } + + section { + background-color: var(--color-surface1); + border-radius: 0.8rem; + + h2, + > ul > li { + padding: 1rem 2rem; + } + + ul, li { + list-style: none; + } + + span { + font-weight: 700; + font-size: 2rem; + margin-bottom: 1rem; + display: block; + } + + li li { + margin-block: 0.5rem; + } + } +} diff --git a/src/pages/Canteen.tsx b/src/pages/Canteen.tsx new file mode 100644 index 0000000..049172e --- /dev/null +++ b/src/pages/Canteen.tsx @@ -0,0 +1,68 @@ +import { RouteSectionProps, createAsync } from '@solidjs/router' +import { Component, For, Show, VoidComponent } from 'solid-js' +import { queryCanteen } from '~/data/canteen.data' +import { Day } from '~/models/canteen' +import styles from './Canteen.module.scss' + +const DAYS = ['Hétfő', 'Kedd', 'Szerda', 'Csütörtök', 'Péntek'] + +type CanteenWeekProps = { + title: string + days: Day[] +} + +const CanteenWeek: VoidComponent = (props) => { + const dataWithDays = () => + DAYS.map((d, i) => ({ + day: d, + menus: props.days[i]?.menus ?? [], + })) + + return ( +
+

{props.title}

+
    + + {(day) => ( +
  • + {day.day} +
      + +
    • Nincs megadva
    • +
      + + {(menu) => ( + +
    • {menu!.menu}
    • +
      + )} +
      +
    +
  • + )} +
    +
+
+ ) +} + +const CanteenPage: Component = () => { + const data = createAsync(() => queryCanteen()) + + return ( + <> +
+

Menza étlap

+ +
+ + + + +
+
+ + ) +} + +export default CanteenPage