Skip to content

Commit

Permalink
wip: sstaars
Browse files Browse the repository at this point in the history
  • Loading branch information
qin-guan committed Sep 25, 2023
1 parent f779efd commit 10220d4
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 6 deletions.
9 changes: 9 additions & 0 deletions components/app/services/event/page.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script setup lang="ts">
import { f7Page } from 'framework7-vue'
</script>

<template>
<f7Page>
Event page
</f7Page>
</template>
98 changes: 97 additions & 1 deletion components/app/services/page.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
<script setup lang="ts">
import { f7NavTitle, f7NavTitleLarge, f7Navbar, f7Page } from 'framework7-vue'
import { FetchError } from 'ofetch'
import { f7, f7Block, f7BlockTitle, f7Button, f7Card, f7CardContent, f7CardFooter, f7CardHeader, f7Icon, f7List, f7ListButton, f7ListGroup, f7ListInput, f7ListItem, f7NavTitle, f7NavTitleLarge, f7Navbar, f7Page, f7PageContent, f7Sheet, f7SwipeoutButton } from 'framework7-vue'

Check failure on line 3 in components/app/services/page.vue

View workflow job for this annotation

GitHub Actions / ci

'f7Card' is defined but never used

Check failure on line 3 in components/app/services/page.vue

View workflow job for this annotation

GitHub Actions / ci

'f7CardContent' is defined but never used

Check failure on line 3 in components/app/services/page.vue

View workflow job for this annotation

GitHub Actions / ci

'f7CardFooter' is defined but never used

Check failure on line 3 in components/app/services/page.vue

View workflow job for this annotation

GitHub Actions / ci

'f7CardHeader' is defined but never used

Check failure on line 3 in components/app/services/page.vue

View workflow job for this annotation

GitHub Actions / ci

'f7ListGroup' is defined but never used

Check failure on line 3 in components/app/services/page.vue

View workflow job for this annotation

GitHub Actions / ci

'f7SwipeoutButton' is defined but never used
const sstaarsStore = useSstaarsStore()
const state = reactive({
sheetOpened: false,
eventId: '',
pending: false,
})
async function click() {
if (state.eventId.length === 0)
return
state.pending = true
try {
const data = await $api(`/api/event/${state.eventId}`)
sstaarsStore.value.previousEvents[data.id] = data.name
state.sheetOpened = false
await nextTick(() => {
f7.views.current.router.navigate(`/app/services/event/${data.id}`, { openIn: 'sheet' })
})
}
catch (err) {
if (err instanceof FetchError) {
f7.toast.show({
text: err.statusMessage,
closeTimeout: 5000,
})
}
}
finally {
state.pending = false
}
}
</script>

<template>
Expand All @@ -12,5 +47,66 @@ import { f7NavTitle, f7NavTitleLarge, f7Navbar, f7Page } from 'framework7-vue'
Alumni Services
</f7NavTitleLarge>
</f7Navbar>

<f7List strong inset>
<f7ListItem class="font-semibold">
SSTAA Registration System (SSTAARS)
</f7ListItem>
<f7ListItem>
Helping out with an SSTAA event? Access the Event Registration System here.
</f7ListItem>
<f7ListButton link="/halp" class="custom-card" @click="state.sheetOpened = true">
<span>
Open
</span>
<f7Icon material="chevron_right" />
</f7ListButton>
</f7List>

<f7Sheet v-model:opened="state.sheetOpened" style="height: auto" swipe-to-close backdrop push>
<f7PageContent>
<f7BlockTitle large>
SSTAARS
</f7BlockTitle>
<f7Block>
<p>
SSTAARS is intended for volunteers helping with SST Alumni Association Event Registration.
</p>
<p>
You will need to have an access code to access SSTAARS.
</p>
<p>
Please reach out to your SSTAA contact if they did not provide you with an access code.
</p>
</f7Block>

<f7List>
<f7ListInput v-model:value="state.eventId" placeholder="Access code" />
<div class="m-4">
<f7Button large fill preloader :loading="state.pending" @click="click">
Continue
</f7Button>
</div>
</f7List>

<f7BlockTitle>
My events
</f7BlockTitle>
<f7List inset strong>
<span v-if="Object.keys(sstaarsStore.previousEvents).length === 0" class="opacity-80">
No previous events.
</span>
<f7ListItem v-for="name, id in sstaarsStore.previousEvents" :key="id" :title="name" :link="`/app/services/event/${id}`" />
</f7List>
</f7PageContent>
</f7Sheet>
</f7Page>
</template>

<style scoped>
:deep(.custom-card > .list-button) {
display: flex !important;
justify-content: space-between !important;
align-items: center !important;
}
</style>
4 changes: 2 additions & 2 deletions composables/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export function useEvents() {
})
}

export function useEvent(id: string) {
export function useEvent(id: MaybeRef<string>) {
const firebaseCurrentUser = useCurrentUser()
const queryClient = useQueryClient()
return useQuery({
queryKey: queryKeyFactory.events,
queryFn: () => $api<EventWithAttendees>('/api/event'),
queryFn: () => $api<EventWithAttendees>(`/api/event/${toValue(id)}`),
enabled: computed(() => !!firebaseCurrentUser.value), // Only run when user exists
placeholderData() {
return queryClient.getQueryData<EventWithAttendees[]>(queryKeyFactory.events)?.find(event => event.id === id)
Expand Down
5 changes: 5 additions & 0 deletions composables/sstaars.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { useStorage } from '@vueuse/core'

export const useSstaarsStore = createGlobalState(() => {
return useStorage('sstaars:data', { previousEvents: {} as Record<string, string> })
})
6 changes: 5 additions & 1 deletion pages/app/[...slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Framework7Vue from 'framework7-vue/bundle'
import { f7App, f7Link, f7Toolbar, f7View, f7Views } from 'framework7-vue'
import { useIsCurrentUserLoaded } from 'vuefire'
import { AppHomePage } from '#components'
import { AppHomePage, AppServicesEventPage } from '#components'
Framework7.use(Framework7Vue)
Expand All @@ -21,6 +21,10 @@ const appRoutes = [
path: '/app',
component: AppHomePage,
},
{
path: '/app/services/event/:id',
component: AppServicesEventPage,
},
]
const dark = useDark()
Expand Down
8 changes: 6 additions & 2 deletions server/api/event/[id].get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export default defineProtectedEventHandler(async (event) => {

if (!result) {
throw createError({
statusCode: 400,
statusMessage: 'Bad request',
statusCode: 404,
statusMessage: 'Not found',
})
}

Expand All @@ -36,4 +36,8 @@ export default defineProtectedEventHandler(async (event) => {
admissionKey,
})),
}
}, {
cache: {
maxAge: 10,
},
})

0 comments on commit 10220d4

Please sign in to comment.