Use a pinia store to manage account state
Refactor the existing scattered code dealing with the account state into a pinia store.
This commit is contained in:
parent
fae8b4e2e4
commit
e722876aae
12 changed files with 126 additions and 98 deletions
|
@ -4,7 +4,7 @@
|
|||
<p>
|
||||
Study carefully, we only hold these events once a year.
|
||||
</p>
|
||||
<p v-if="!sessionStore.account">
|
||||
<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>
|
||||
|
@ -12,7 +12,7 @@
|
|||
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="sessionStore.account">
|
||||
<label v-if="accountStore.valid">
|
||||
Filter:
|
||||
<select
|
||||
v-model="filter"
|
||||
|
@ -26,11 +26,11 @@
|
|||
:selected='filter === "my-schedule"'
|
||||
>My Schedule</option>
|
||||
<option
|
||||
v-if="isCrew"
|
||||
v-if="accountStore.isCrew"
|
||||
value="assigned"
|
||||
:selected='filter === "assigned"'
|
||||
>Assigned to Me</option>
|
||||
<optgroup v-if="isCrew && accounts" label="Crew">
|
||||
<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"
|
||||
|
@ -57,13 +57,9 @@
|
|||
<script setup lang="ts">
|
||||
import type { ShiftSlot, TimeSlot } from '~/shared/types/schedule';
|
||||
|
||||
const sessionStore = useSessionStore();
|
||||
const accountStore = useAccountStore();
|
||||
const { data: accounts } = await useAccounts();
|
||||
const schedule = await useSchedule();
|
||||
const isCrew = computed(() => (
|
||||
sessionStore.account?.type === "crew"
|
||||
|| sessionStore.account?.type === "admin"
|
||||
));
|
||||
|
||||
const route = useRoute();
|
||||
const filter = computed({
|
||||
|
@ -78,12 +74,12 @@ const filter = computed({
|
|||
});
|
||||
|
||||
const eventSlotFilter = computed(() => {
|
||||
if (filter.value === undefined || !sessionStore.account) {
|
||||
if (filter.value === undefined || !accountStore.valid) {
|
||||
return () => true;
|
||||
}
|
||||
const aid = sessionStore.account?.id;
|
||||
const aid = accountStore.id;
|
||||
if (filter.value === "my-schedule") {
|
||||
const ids = new Set(sessionStore.account?.interestedIds);
|
||||
const ids = new Set(accountStore.interestedIds);
|
||||
for (const event of schedule.value.events) {
|
||||
if (ids.has(event.id)) {
|
||||
for (const slot of event.slots) {
|
||||
|
@ -103,11 +99,11 @@ const eventSlotFilter = computed(() => {
|
|||
return () => false;
|
||||
});
|
||||
const shiftSlotFilter = computed(() => {
|
||||
if (filter.value === undefined || !sessionStore.account) {
|
||||
if (filter.value === undefined || !accountStore.valid) {
|
||||
return () => true;
|
||||
}
|
||||
if (filter.value === "my-schedule" || filter.value === "assigned") {
|
||||
const aid = sessionStore.account?.id;
|
||||
const aid = accountStore.id;
|
||||
return (slot: ShiftSlot) => slot.assigned?.some(id => id === aid) || false;
|
||||
}
|
||||
if (filter.value.startsWith("crew-")) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue