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