feat: wellness settings (#927)

Co-authored-by: 三咲智子 Kevin Deng <sxzz@sxzz.moe>
This commit is contained in:
wheat 2023-01-10 09:45:17 -05:00 committed by GitHub
parent 81c8a74748
commit ba9a91a34e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 95 additions and 6 deletions

View file

@ -1,9 +1,11 @@
import type { FeatureFlags } from './featureFlags'
import type { WellnessSettings } from './wellness'
import type { ColorMode, FontSize } from '~/types'
import { STORAGE_KEY_SETTINGS } from '~/constants'
export interface UserSettings {
featureFlags: Partial<FeatureFlags>
wellnessSettings: Partial<WellnessSettings>
colorMode?: ColorMode
fontSize?: FontSize
lang?: string
@ -13,6 +15,7 @@ export interface UserSettings {
export function getDefaultUserSettings(): UserSettings {
return {
featureFlags: {},
wellnessSettings: {},
}
}

View file

@ -0,0 +1,36 @@
import type { Ref } from 'vue'
import { userSettings } from '.'
export interface WellnessSettings {
hideBoostCount: boolean
hideFavoriteCount: boolean
hideFollowerCount: boolean
}
export type WellnessSettingsMap = Record<string, WellnessSettings>
const DEFAULT_WELLNESS_SETTINGS: WellnessSettings = {
hideBoostCount: false,
hideFavoriteCount: false,
hideFollowerCount: false,
}
export function useWellnessSetting<T extends keyof WellnessSettings>(name: T): Ref<WellnessSettings[T]> {
return computed({
get() {
return getWellnessSetting(name)
},
set(value) {
if (userSettings.value)
userSettings.value.wellnessSettings[name] = value
},
})
}
export function getWellnessSetting<T extends keyof WellnessSettings>(name: T): WellnessSettings[T] {
return userSettings.value?.wellnessSettings?.[name] ?? DEFAULT_WELLNESS_SETTINGS[name]
}
export function toggleWellnessSetting(key: keyof WellnessSettings) {
const flag = useWellnessSetting(key)
flag.value = !flag.value
}