♻️ Makes feature flags be fetched over socket
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import { api } from '$lib/api'
|
|
||||||
import { notifications } from '$lib/components/toasts/notifications'
|
import { notifications } from '$lib/components/toasts/notifications'
|
||||||
import Kinematic from '$lib/kinematic'
|
import Kinematic from '$lib/kinematic'
|
||||||
import { persistentStore } from '$lib/utilities'
|
import { persistentStore } from '$lib/utilities'
|
||||||
import { derived, type Writable } from 'svelte/store'
|
import { derived, type Writable } from 'svelte/store'
|
||||||
import { resolve } from '$app/paths'
|
import { resolve } from '$app/paths'
|
||||||
|
import { socket } from '$lib/stores'
|
||||||
|
|
||||||
let featureFlagsStore: Writable<Record<string, boolean | string>>
|
let featureFlagsStore: Writable<Record<string, boolean | string>>
|
||||||
|
|
||||||
@@ -11,12 +11,20 @@ export function useFeatureFlags() {
|
|||||||
if (!featureFlagsStore) {
|
if (!featureFlagsStore) {
|
||||||
featureFlagsStore = persistentStore<Record<string, boolean | string>>('FeatureFlags', {})
|
featureFlagsStore = persistentStore<Record<string, boolean | string>>('FeatureFlags', {})
|
||||||
|
|
||||||
api.get<Record<string, boolean>>('/api/features').then(result => {
|
socket
|
||||||
if (result.isOk()) featureFlagsStore.set(result.inner)
|
.request({ featuresDataRequest: {} })
|
||||||
else {
|
.then(response => {
|
||||||
notifications.error('Feature flag could not be fetched', 2500)
|
if (response.featuresDataResponse) {
|
||||||
|
featureFlagsStore.set(
|
||||||
|
response.featuresDataResponse as unknown as Record<string, boolean | string>
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
notifications.error('Feature flags could not be fetched', 2500)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.catch(() => {
|
||||||
|
notifications.error('Feature flags could not be fetched', 2500)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return featureFlagsStore
|
return featureFlagsStore
|
||||||
|
|||||||
Reference in New Issue
Block a user