diff --git a/src/lib/util/loading.svelte.ts b/src/lib/util/loading.svelte.ts new file mode 100644 index 00000000..2ba36e22 --- /dev/null +++ b/src/lib/util/loading.svelte.ts @@ -0,0 +1,14 @@ +import type { LoadingState } from '$lib/types'; + +export const loadingState = $state({ loading: false }); + +export const initLoading = async (message: string, task: Promise): Promise => { + loadingState.loading = true; + loadingState.message = message; + try { + return await task; + } finally { + loadingState.loading = false; + loadingState.message = undefined; + } +}; diff --git a/src/lib/util/loading.ts b/src/lib/util/loading.ts deleted file mode 100644 index cebe1947..00000000 --- a/src/lib/util/loading.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { writable } from 'svelte/store'; -import type { Writable } from 'svelte/store'; -import type { LoadingState } from '$lib/types'; - -const defaultLoading: LoadingState = { - loading: false -}; - -export const loadingStateStore: Writable = writable(defaultLoading); -export const initLoading = async (message: string, task: Promise): Promise => { - loadingStateStore.set({ - loading: true, - message - }); - const result: T = await task; - loadingStateStore.set({ - loading: false - }); - return result; -}; diff --git a/src/lib/util/util.ts b/src/lib/util/util.ts index 8c232607..f9fb2a4e 100644 --- a/src/lib/util/util.ts +++ b/src/lib/util/util.ts @@ -1,7 +1,7 @@ import { C } from '$/constants'; import { env } from './env'; import { loadDataFromUrl } from './fileLoaders/loader'; -import { initLoading } from './loading'; +import { initLoading } from './loading.svelte'; import { isOnMermaidAI } from './migration/domainMigration'; import { applyMigrations } from './migrations'; import { initURLSubscription, loadState, updateCodeStore, verifyState } from './state.svelte'; diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 6fe36d8d..b23fc433 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -1,6 +1,6 @@