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.
This commit is contained in:
parent
ce9f758f84
commit
bb450fd583
15 changed files with 488 additions and 1297 deletions
|
@ -1,11 +1,5 @@
|
|||
<template>
|
||||
<main v-if="schedule.deleted">
|
||||
<h1>Error</h1>
|
||||
<p>
|
||||
Schedule has been deleted.
|
||||
</p>
|
||||
</main>
|
||||
<main v-else>
|
||||
<main>
|
||||
<h1>Schedule & Events</h1>
|
||||
<p>
|
||||
Study carefully, we only hold these events once a year.
|
||||
|
@ -48,10 +42,10 @@
|
|||
</label>
|
||||
<Timetable :schedule :eventSlotFilter :shiftSlotFilter />
|
||||
<h2>Events</h2>
|
||||
<EventCard v-for="event in schedule.events?.filter(e => !e.deleted && e.slots.some(eventSlotFilter))" :event/>
|
||||
<EventCard v-for="event in [...schedule.events.values()].filter(e => !e.deleted && [...e.slots.values()].some(eventSlotFilter))" :event/>
|
||||
<h2>Locations</h2>
|
||||
<ul>
|
||||
<li v-for="location in schedule.locations?.filter(l => !l.deleted)" :key="location.id">
|
||||
<li v-for="location in schedule.locations.values()" :key="location.id">
|
||||
<h3>{{ location.name }}</h3>
|
||||
{{ location.description ?? "No description provided" }}
|
||||
</li>
|
||||
|
@ -60,8 +54,6 @@
|
|||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { ApiScheduleShiftSlot, ApiScheduleEventSlot } from '~/shared/types/api';
|
||||
|
||||
const accountStore = useAccountStore();
|
||||
const { data: accounts } = await useAccounts();
|
||||
const schedule = await useSchedule();
|
||||
|
@ -85,21 +77,21 @@ const eventSlotFilter = computed(() => {
|
|||
const aid = accountStore.id;
|
||||
if (filter.value === "my-schedule") {
|
||||
const slotIds = new Set(accountStore.interestedEventSlotIds);
|
||||
for (const event of schedule.value.events ?? []) {
|
||||
for (const event of schedule.value.events.values()) {
|
||||
if (!event.deleted && accountStore.interestedEventIds.has(event.id)) {
|
||||
for (const slot of event.slots) {
|
||||
for (const slot of event.slots.values()) {
|
||||
slotIds.add(slot.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (slot: ApiScheduleEventSlot) => slotIds.has(slot.id) || slot.assigned?.some(id => id === aid) || false;
|
||||
return (slot: ClientScheduleEventSlot) => slotIds.has(slot.id) || slot.assigned.has(aid!) || false;
|
||||
}
|
||||
if (filter.value === "assigned") {
|
||||
return (slot: ApiScheduleEventSlot) => slot.assigned?.some(id => id === aid) || false;
|
||||
return (slot: ClientScheduleEventSlot) => slot.assigned.has(aid!) || false;
|
||||
}
|
||||
if (filter.value.startsWith("crew-")) {
|
||||
const cid = parseInt(filter.value.slice(5));
|
||||
return (slot: ApiScheduleEventSlot) => slot.assigned?.some(id => id === cid) || false;
|
||||
return (slot: ClientScheduleEventSlot) => slot.assigned.has(cid) || false;
|
||||
}
|
||||
return () => false;
|
||||
});
|
||||
|
@ -109,11 +101,11 @@ const shiftSlotFilter = computed(() => {
|
|||
}
|
||||
if (filter.value === "my-schedule" || filter.value === "assigned") {
|
||||
const aid = accountStore.id;
|
||||
return (slot: ApiScheduleShiftSlot) => slot.assigned?.some(id => id === aid) || false;
|
||||
return (slot: ClientScheduleShiftSlot) => slot.assigned.has(aid!) || false;
|
||||
}
|
||||
if (filter.value.startsWith("crew-")) {
|
||||
const cid = parseInt(filter.value.slice(5));
|
||||
return (slot: ApiScheduleShiftSlot) => slot.assigned?.some(id => id === cid) || false;
|
||||
return (slot: ClientScheduleShiftSlot) => slot.assigned.has(cid) || false;
|
||||
}
|
||||
return () => false;
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue