elk/composables/featureFlags.ts

39 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-11-28 23:57:27 +01:00
import { STORAGE_KEY_FEATURE_FLAGS } from '~/constants'
export interface FeatureFlags {
experimentalVirtualScroll: boolean
2022-12-17 22:11:39 +01:00
experimentalGitHubCards: boolean
2022-12-27 21:07:19 +01:00
experimentalUserPicker: boolean
2022-11-28 23:57:27 +01:00
}
export type FeatureFlagsMap = Record<string, FeatureFlags>
export function getDefaultFeatureFlags(): FeatureFlags {
return {
experimentalVirtualScroll: false,
2022-12-17 22:11:39 +01:00
experimentalGitHubCards: true,
2022-12-27 21:07:19 +01:00
experimentalUserPicker: true,
2022-11-28 23:57:27 +01:00
}
}
2022-12-24 00:19:17 +01:00
export const currentUserFeatureFlags = process.server
? computed(getDefaultFeatureFlags)
: useUserLocalStorage(STORAGE_KEY_FEATURE_FLAGS, getDefaultFeatureFlags)
2022-11-28 23:57:27 +01:00
export function useFeatureFlags() {
const featureFlags = currentUserFeatureFlags.value
return featureFlags
}
export function toggleFeatureFlag(key: keyof FeatureFlags) {
const featureFlags = currentUserFeatureFlags.value
if (featureFlags[key])
featureFlags[key] = !featureFlags[key]
else
featureFlags[key] = true
}
2022-12-27 21:07:19 +01:00
const userPicker = eagerComputed(() => useFeatureFlags().experimentalUserPicker)
export const showUserPicker = computed(() => useUsers().value.length > 1 && userPicker.value)