owltide/pages/schedule.vue
Hornwitser fe06d0d6bd
All checks were successful
/ build (push) Successful in 2m5s
/ deploy (push) Successful in 16s
Refactor API types and sync logic
Rename and refactor the types passed over the API to be based on an
entity that's either living or a tombstone.  A living entity has a
deleted property that's either undefined or false, while a tombstone
has a deleted property set to true.  All entities have a numeric id
and an updatedAt timestamp.

To sync entities, an array of replacements are passed around. Living
entities are replaced with tombstones when they're deleted. And
tombstones are replaced with living entities when restored.
2025-06-11 21:05:17 +02:00

120 lines
3.7 KiB
Vue

<template>
<main v-if="schedule.deleted">
<h1>Error</h1>
<p>
Schedule has been deleted.
</p>
</main>
<main v-else>
<h1>Schedule & Events</h1>
<p>
Study carefully, we only hold these events once a year.
</p>
<p v-if="!accountStore.valid">
<NuxtLink to="/login">Login</NuxtLink> or <NuxtLink to="/login#create-account">Create an account</NuxtLink>
to get notified about updates to the schedule.
</p>
<p v-else>
Check out your <NuxtLink to="/account/settings">Account Setting</NuxtLink> to set up notifications for changes to schedule.
</p>
<h2>Schedule</h2>
<label v-if="accountStore.valid">
Filter:
<select
v-model="filter"
>
<option
:value="undefined"
:selected="filter === undefined"
>&lt;All events&gt;</option>
<option
value="my-schedule"
:selected='filter === "my-schedule"'
>My Schedule</option>
<option
v-if="accountStore.isCrew"
value="assigned"
:selected='filter === "assigned"'
>Assigned to Me</option>
<optgroup v-if="accountStore.isCrew && accounts" label="Crew">
<option
v-for="account in accounts.filter(a => a.type === 'crew' || a.type === 'admin')"
:key="account.id"
:value="`crew-${account.id}`"
:selected="filter === `crew-${account.id}`"
>{{ account.name }}</option>
</optgroup>
</select>
</label>
<Timetable :schedule :eventSlotFilter :shiftSlotFilter />
<h2>Events</h2>
<EventCard v-for="event in schedule.events?.filter(e => !e.deleted && e.slots.some(eventSlotFilter))" :event/>
<h2>Locations</h2>
<ul>
<li v-for="location in schedule.locations?.filter(l => !l.deleted)" :key="location.id">
<h3>{{ location.name }}</h3>
{{ location.description ?? "No description provided" }}
</li>
</ul>
</main>
</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();
const route = useRoute();
const filter = computed({
get: () => queryToString(route.query.filter),
set: (value: string | undefined) => navigateTo({
path: route.path,
query: {
...route.query,
filter: value,
},
}),
});
const eventSlotFilter = computed(() => {
if (filter.value === undefined || !accountStore.valid || schedule.value.deleted) {
return () => true;
}
const aid = accountStore.id;
if (filter.value === "my-schedule") {
const slotIds = new Set(accountStore.interestedEventSlotIds);
for (const event of schedule.value.events ?? []) {
if (!event.deleted && accountStore.interestedEventIds.has(event.id)) {
for (const slot of event.slots) {
slotIds.add(slot.id);
}
}
}
return (slot: ApiScheduleEventSlot) => slotIds.has(slot.id) || slot.assigned?.some(id => id === aid) || false;
}
if (filter.value === "assigned") {
return (slot: ApiScheduleEventSlot) => slot.assigned?.some(id => id === 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 () => false;
});
const shiftSlotFilter = computed(() => {
if (filter.value === undefined || !accountStore.valid) {
return () => true;
}
if (filter.value === "my-schedule" || filter.value === "assigned") {
const aid = accountStore.id;
return (slot: ApiScheduleShiftSlot) => slot.assigned?.some(id => id === 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 () => false;
});
</script>