From bb450fd5830de8772cce8a80eb3f62b5b51ba6ea Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 14 Jun 2025 19:22:53 +0200 Subject: [PATCH] Refactor to use ClientSchedule on client Use the ClientSchedule data structure for deserialising and tracking edit state on the client instead of trying to directly deal with the ApiSchedule type which is not build for ease of edits or rendering. --- components/AssignedCrew.vue | 10 +- components/EventCard.vue | 22 +- components/EventsTable.vue | 147 +++------- components/LocationsTable.vue | 143 +++------- components/RolesTable.vue | 145 +++------- components/ScheduleTable.vue | 435 ++++++----------------------- components/ShiftScheduleTable.vue | 440 +++++++----------------------- components/ShiftsTable.vue | 173 +++--------- components/Timetable.vue | 153 +++++------ pages/edit.vue | 41 ++- pages/schedule.vue | 28 +- shared/utils/functions.ts | 4 +- shared/utils/luxon.ts | 4 +- stores/schedules.ts | 31 +-- utils/client-schedule.ts | 9 + 15 files changed, 488 insertions(+), 1297 deletions(-) diff --git a/components/AssignedCrew.vue b/components/AssignedCrew.vue index 3d7fc0d..c276009 100644 --- a/components/AssignedCrew.vue +++ b/components/AssignedCrew.vue @@ -5,7 +5,7 @@ @@ -26,9 +26,9 @@ defineProps<{ }>(); const { data: accounts } = useAccounts(); const accountsById = computed(() => new Map(accounts.value?.map?.(a => [a.id, a]))); -const assignedIds = defineModel({ required: true }); +const assignedIds = defineModel>({ required: true }); const assigned = computed( - () => assignedIds.value.map( + () => [...assignedIds.value].map( id => accountsById.value.get(id) ?? { id, name: String(id) } ) ); @@ -43,8 +43,8 @@ function addCrew() { return; const account = crewByName.value.get(addName.value); if (account) { - if (!assignedIds.value.some(id => id === account.id)) { - assignedIds.value = [...assignedIds.value, account.id]; + if (!assignedIds.value.has(account.id)) { + assignedIds.value = new Set([...assignedIds.value, account.id]); } else { alert(`${addName.value} has already been added`); } diff --git a/components/EventCard.vue b/components/EventCard.vue index b0345e7..875abab 100644 --- a/components/EventCard.vue +++ b/components/EventCard.vue @@ -1,10 +1,5 @@