From 692df8913fe616820e6c17e3269a3d607263f936 Mon Sep 17 00:00:00 2001 From: julienrousseau Date: Sun, 2 Mar 2025 12:06:52 -0500 Subject: [PATCH] adjusted implementation --- packages/web/src/components/Calendar.astro | 52 +++++++++++----------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/packages/web/src/components/Calendar.astro b/packages/web/src/components/Calendar.astro index ed4df1a..c587fd4 100644 --- a/packages/web/src/components/Calendar.astro +++ b/packages/web/src/components/Calendar.astro @@ -7,17 +7,22 @@ import { weekdays } from "../lib/constants"; interface Props { activities: Activity[][]; + min?: number; + max?: number; + interval?: number; } -const timeMin = 8; -const timeMax = 22; -const minutesPerTick = 60; - type ActivityRender = Activity & { inset: number; adjacent?: { position: number; count: number }; }; +const { + min: timeMin = 8, + max: timeMax = 22, + interval: minutesPerTick = 60, +} = Astro.props; + const activities = Astro.props.activities.map((w) => { const weekday: ActivityRender[] = w .sort((a, b) => decimal(a.time.start) - decimal(b.time.start)) @@ -45,10 +50,8 @@ const activities = Astro.props.activities.map((w) => { adjacents.size === adjacentCount || (adjacents.size > 0 && i === weekday.length - 1) ) { - let position = 0; - for (const activity of adjacents) { + for (const [position, activity] of [...adjacents].entries()) { activity.adjacent = { position, count: adjacents.size }; - position++; } adjacents.clear(); } @@ -209,14 +212,9 @@ 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)}`, - ), - )} + data-except-dates={activity.lessons.exceptions + .sort((a, b) => a.getTime() - b.getTime()) + .map((date) => dateFormatter.format(date))} >