From b7fa22b018ad0415a4a6205b9a3f26fd30a0f0d8 Mon Sep 17 00:00:00 2001 From: Stephen Adamson Date: Sun, 5 Jul 2026 22:26:18 +0100 Subject: [PATCH] refactor: accept defaultHours prop in WeeklySchedule and TimeBlockers Add optional defaultHours prop to accept pre-fetched data from parent page. Standardise select element styling with shadow-xs, focus-visible ring, and consistent padding. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- .../lib/components/admin/TimeBlockers.svelte | 23 +++++++++++----- .../components/admin/WeeklySchedule.svelte | 27 ++++++++++++++++--- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/frontend/src/lib/components/admin/TimeBlockers.svelte b/frontend/src/lib/components/admin/TimeBlockers.svelte index 7026869..31e1f23 100644 --- a/frontend/src/lib/components/admin/TimeBlockers.svelte +++ b/frontend/src/lib/components/admin/TimeBlockers.svelte @@ -53,9 +53,10 @@ openUserModal?: (userId: string) => void; openBookingModal?: (bookingId: string) => void; rescheduleVersion?: number; + defaultHours?: WorkingHourRow[]; } - const { openUserModal, openBookingModal, rescheduleVersion = 0 }: Props = $props(); + const { openUserModal, openBookingModal, rescheduleVersion = 0, defaultHours: defaultHoursProp }: Props = $props(); const PAGE_SIZE = 5; @@ -501,7 +502,17 @@ $effect(() => { fetchBlockers(); - fetchDefaultHours(); + }); + + $effect(() => { + if (defaultHoursProp !== undefined) { + if (defaultHoursProp.length > 0) { + defaultHours = defaultHoursProp; + } + hoursLoading = false; + } else { + fetchDefaultHours(); + } }); $effect(() => { @@ -763,7 +774,7 @@

{:else} { const p = parseSelectValue(endSelectValue); endHour = p.hour; diff --git a/frontend/src/lib/components/admin/WeeklySchedule.svelte b/frontend/src/lib/components/admin/WeeklySchedule.svelte index 564aa4f..1fa52b4 100644 --- a/frontend/src/lib/components/admin/WeeklySchedule.svelte +++ b/frontend/src/lib/components/admin/WeeklySchedule.svelte @@ -13,6 +13,13 @@ const TIME15 = ['00', '15', '30', '45']; + // =============== Props =============== + interface Props { + defaultHours?: Array<{ weekday: number; startTime: string; endTime: string; isOpen: boolean }>; + } + + let { defaultHours: defaultHoursProp }: Props = $props(); + // =============== Types =============== type WorkingHourRow = { weekday: number; @@ -192,7 +199,21 @@ // =============== Effects =============== $effect(() => { - if (browser) { + if (defaultHoursProp !== undefined) { + // Parent provides data via prop — map camelCase to display format + if (defaultHoursProp.length > 0) { + defaultHours = defaultHoursProp.map( + (hour: { weekday: number; startTime: string; endTime: string; isOpen: boolean }) => ({ + weekday: hour.weekday, + start_time: formatTime(hour.startTime), + end_time: formatTime(hour.endTime), + is_open: hour.isOpen + }) + ); + } + defaultHoursIsLoading = false; + } else if (browser) { + // Backward compatible: self-fetch fetchDefaultHours(); } }); @@ -485,7 +506,7 @@ {#each Array(24) as _, hour (hour)} {#each TIME15 as min (min)}