diff --git a/src/main.js b/src/main.js index 2e02d984107cb06aa85648f1e07af06280dfb2d0..3d130fd837d5c8992ea5df6797340b7dd8020941 100644 --- a/src/main.js +++ b/src/main.js @@ -1,6 +1,6 @@ import BootstrapVue from 'bootstrap-vue' import { createPinia } from 'pinia' -import { createApp } from 'vue' +import { createApp, reactive, watchEffect } from 'vue' import VueToast from 'vue-toast-notification' import VueLogger from 'vuejs-logger' @@ -15,6 +15,8 @@ import '../node_modules/bootstrap/scss/bootstrap.scss' import './assets/custom.scss' import './assets/styles/tailwind.css' import { shouldLog } from '@/utilities' +import { useAuthStore } from '@/stores/auth' +import { useHostStore } from '@/stores/hosts' const pinia = createPinia() const app = createApp(App) @@ -44,3 +46,16 @@ app.use(TranslationPlugin) app.use(VueToast, { position: 'bottom-left' }) store.$log = app.$log app.mount('#app') + +const authStore = reactive(useAuthStore()) +const hostStore = useHostStore() + +watchEffect(async () => { + if (authStore.currentUser) { + try { + await Promise.allSettled([hostStore.list()]) + } catch (e) { + console.error('unable to load base state from stores', e) + } + } +}) diff --git a/src/stores/hosts.ts b/src/stores/hosts.ts new file mode 100644 index 0000000000000000000000000000000000000000..c556e04e1fed9c6510de00e5103bcd260991a77a --- /dev/null +++ b/src/stores/hosts.ts @@ -0,0 +1,14 @@ +import { defineStore } from 'pinia' +import { steeringAuthInit } from '@/stores/auth' +import { APIListUnpaginated, APIRetrieve, createExtendableAPI, createSteeringURL } from '@/api' +import { Host } from '@/types' + +export const useHostStore = defineStore('hosts', () => { + const endpoint = createSteeringURL.prefix('hosts') + const { base, ...api } = createExtendableAPI<Host>(endpoint, steeringAuthInit) + return { + ...base, + ...APIListUnpaginated(api), + ...APIRetrieve(api), + } +}) diff --git a/src/types.ts b/src/types.ts index a14dc1129546de0aed76f874f5c232bb3490c973..3b7663ed4e83b94dbb45e941bd095f3781c48276 100644 --- a/src/types.ts +++ b/src/types.ts @@ -20,3 +20,4 @@ export type TimeSlot = Required<steeringComponents['schemas']['TimeSlot']> export type Show = Required<steeringComponents['schemas']['Show']> export type Playlist = Required<tankComponents['schemas']['store.Playlist']> export type Schedule = Required<steeringComponents['schemas']['Schedule']> +export type Host = Required<steeringComponents['schemas']['Host']>