1
0
Fork 1
mirror of https://github.com/elk-zone/elk.git synced 2024-11-20 07:49:57 +00:00
elk/composables/featureFlags.ts

39 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-11-28 22:57:27 +00:00
import { STORAGE_KEY_FEATURE_FLAGS } from '~/constants'
export interface FeatureFlags {
experimentalVirtualScroll: boolean
experimentalAvatarOnAvatar: boolean
2022-12-17 21:11:39 +00:00
experimentalGitHubCards: boolean
experimentalUserSwitcherSidebar: boolean
2022-11-28 22:57:27 +00:00
}
export type FeatureFlagsMap = Record<string, FeatureFlags>
export function getDefaultFeatureFlags(): FeatureFlags {
return {
experimentalVirtualScroll: false,
experimentalAvatarOnAvatar: true,
2022-12-17 21:11:39 +00:00
experimentalGitHubCards: true,
experimentalUserSwitcherSidebar: true,
2022-11-28 22:57:27 +00:00
}
}
export const currentUserFeatureFlags = process.server ? computed(getDefaultFeatureFlags) : useUserLocalStorage(STORAGE_KEY_FEATURE_FLAGS, getDefaultFeatureFlags)
2022-11-28 22:57:27 +00: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
}
const userSwitcherSidebar = eagerComputed(() => useFeatureFlags().experimentalUserSwitcherSidebar)
export const showUserSwitcherSidebar = computed(() => useUsers().value.length > 1 && userSwitcherSidebar.value)