From 64b0f5e80f4bd3060b246834875cc39840a2fb81 Mon Sep 17 00:00:00 2001 From: julienrousseau Date: Sat, 1 Mar 2025 23:32:15 -0500 Subject: [PATCH] added exception dates to calendar --- packages/common/src/models/activities.ts | 27 +++++++++++-------- packages/web/src/components/Calendar.astro | 31 +++++++++++++++++++++- packages/web/src/lib/formatters.ts | 2 ++ packages/web/src/pages/horaire.astro | 11 ++++++++ 4 files changed, 59 insertions(+), 12 deletions(-) diff --git a/packages/common/src/models/activities.ts b/packages/common/src/models/activities.ts index ce9d5e4..2bcc2f8 100644 --- a/packages/common/src/models/activities.ts +++ b/packages/common/src/models/activities.ts @@ -1,16 +1,21 @@ import { z } from "zod"; -export const Time = z.object({ hour: z.number(), minute: z.number() }) +export const Time = z.object({ hour: z.number(), minute: z.number() }); export const Activity = z.object({ - type: z.number(), - title: z.string(), - subtitle: z.string().optional(), - time: z.object({ start: Time, end: Time }), - lessons: z.object({ count: z.number(), first: z.date(), last: z.date() }), - price: z.number(), - color: z.string() -}) + type: z.number(), + title: z.string(), + subtitle: z.string().optional(), + time: z.object({ start: Time, end: Time }), + lessons: z.object({ + count: z.number(), + first: z.date(), + last: z.date(), + exceptions: z.array(z.date()), + }), + price: z.number(), + color: z.string(), +}); -export type Time = z.infer -export type Activity = z.infer +export type Time = z.infer; +export type Activity = z.infer; diff --git a/packages/web/src/components/Calendar.astro b/packages/web/src/components/Calendar.astro index 1d16a94..ed4df1a 100644 --- a/packages/web/src/components/Calendar.astro +++ b/packages/web/src/components/Calendar.astro @@ -2,7 +2,7 @@ import type { Activity, Time } from "common"; import { gcd } from "../lib/maths"; import { cn, dark, contrast } from "../lib/utils"; -import { dateFormatter } from "../lib/formatters"; +import { dateFormatter, listFormatter } from "../lib/formatters"; import { weekdays } from "../lib/constants"; interface Props { @@ -209,6 +209,14 @@ function shiftWeekday(weekday: number) { data-amount={activity.price.toFixed(2)} data-lessons={activity.lessons.count} data-weekday={weekdays[weekday]} + data-except-dates={listFormatter.format( + activity.lessons.exceptions + .sort((a, b) => a.getTime() - b.getTime()) + .map( + (date) => + `${dateFormatter.format(date)}`, + ), + )} >