🚩 Expands feature flag handling with persistence

This commit is contained in:
Rune Harlyk
2025-07-11 12:34:53 +02:00
committed by Rune Harlyk
parent a3be035f98
commit 2eab893dd7
3 changed files with 43 additions and 24 deletions
+10 -9
View File
@@ -1,20 +1,21 @@
import { api } from '$lib/api';
import { notifications } from '$lib/components/toasts/notifications';
import { writable, type Writable } from 'svelte/store';
import { api } from '$lib/api'
import { notifications } from '$lib/components/toasts/notifications'
import { persistentStore } from '$lib/utilities'
import { type Writable } from 'svelte/store'
let featureFlagsStore: Writable<Record<string, boolean | string>>;
let featureFlagsStore: Writable<Record<string, boolean | string>>
export function useFeatureFlags() {
if (!featureFlagsStore) {
featureFlagsStore = writable<Record<string, boolean | string>>({});
featureFlagsStore = persistentStore<Record<string, boolean | string>>('FeatureFlags', {})
api.get<Record<string, boolean>>('/api/features').then(result => {
if (result.isOk()) featureFlagsStore.set(result.inner);
if (result.isOk()) featureFlagsStore.set(result.inner)
else {
notifications.error('Feature flag could not be fetched', 2500);
notifications.error('Feature flag could not be fetched', 2500)
}
});
})
}
return featureFlagsStore;
return featureFlagsStore
}