diff options
| author | Leonardo Bishop <me@leonardobishop.com> | 2025-08-14 18:07:12 +0100 |
|---|---|---|
| committer | Leonardo Bishop <me@leonardobishop.com> | 2025-08-14 18:07:12 +0100 |
| commit | 4697556cac819c47d068819b9fc9c3b4ea84e279 (patch) | |
| tree | b832d8fc6b643a8b9d0eeca35c1268e1649da731 /web/composables/fetch-schedule.ts | |
| parent | dd49c9205bb04844b686b9c3396c40eb49d25826 (diff) | |
Merge confplanner-web and replace fiber with native net/http
Diffstat (limited to 'web/composables/fetch-schedule.ts')
| -rw-r--r-- | web/composables/fetch-schedule.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/web/composables/fetch-schedule.ts b/web/composables/fetch-schedule.ts new file mode 100644 index 0000000..c061d92 --- /dev/null +++ b/web/composables/fetch-schedule.ts @@ -0,0 +1,27 @@ +export default function useFetchFavourites() { + const scheduleStore = useScheduleStore(); + const errorStore = useErrorStore(); + const config = useRuntimeConfig(); + + useFetch(config.public.baseURL + '/schedule', { + method: 'GET', + server: false, + lazy: true, + onResponse: ({ response }) => { + if (!response.ok) { + if (response.status === 401) { + navigateTo({ name: 'login', state: { error: 'Sorry, your session has expired' } }); + } else { + errorStore.setError(response._data.message || 'An unknown error occurred'); + } + } + + if (response._data) { + scheduleStore.setSchedule((response._data as any).data.schedule); + errorStore.setError("Schedule set"); + } else { + errorStore.setError("Invalid response returned by server"); + } + }, + }); +}
\ No newline at end of file |
