Use a pinia store to manage session state
Replace the convoluted useAccountSession composable with a pinia store that in addition allows for the consolidation of all session related functions to grouped into one module.
This commit is contained in:
parent
c47452a8b4
commit
fae8b4e2e4
21 changed files with 181 additions and 118 deletions
|
@ -4,7 +4,7 @@
|
|||
<p>
|
||||
Study carefully, we only hold these events once a year.
|
||||
</p>
|
||||
<p v-if="!session">
|
||||
<p v-if="!sessionStore.account">
|
||||
<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="session">
|
||||
<label v-if="sessionStore.account">
|
||||
Filter:
|
||||
<select
|
||||
v-model="filter"
|
||||
|
@ -57,12 +57,12 @@
|
|||
<script setup lang="ts">
|
||||
import type { ShiftSlot, TimeSlot } from '~/shared/types/schedule';
|
||||
|
||||
const { data: session } = await useAccountSession();
|
||||
const sessionStore = useSessionStore();
|
||||
const { data: accounts } = await useAccounts();
|
||||
const schedule = await useSchedule();
|
||||
const isCrew = computed(() => (
|
||||
session.value?.account?.type === "crew"
|
||||
|| session.value?.account?.type === "admin"
|
||||
sessionStore.account?.type === "crew"
|
||||
|| sessionStore.account?.type === "admin"
|
||||
));
|
||||
|
||||
const route = useRoute();
|
||||
|
@ -78,12 +78,12 @@ const filter = computed({
|
|||
});
|
||||
|
||||
const eventSlotFilter = computed(() => {
|
||||
if (filter.value === undefined || !session.value) {
|
||||
if (filter.value === undefined || !sessionStore.account) {
|
||||
return () => true;
|
||||
}
|
||||
const aid = session.value?.account?.id;
|
||||
const aid = sessionStore.account?.id;
|
||||
if (filter.value === "my-schedule") {
|
||||
const ids = new Set(session.value?.account?.interestedIds);
|
||||
const ids = new Set(sessionStore.account?.interestedIds);
|
||||
for (const event of schedule.value.events) {
|
||||
if (ids.has(event.id)) {
|
||||
for (const slot of event.slots) {
|
||||
|
@ -103,11 +103,11 @@ const eventSlotFilter = computed(() => {
|
|||
return () => false;
|
||||
});
|
||||
const shiftSlotFilter = computed(() => {
|
||||
if (filter.value === undefined || !session.value) {
|
||||
if (filter.value === undefined || !sessionStore.account) {
|
||||
return () => true;
|
||||
}
|
||||
if (filter.value === "my-schedule" || filter.value === "assigned") {
|
||||
const aid = session.value?.account?.id;
|
||||
const aid = sessionStore.account?.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