feat: wellness settings (#927)
Co-authored-by: 三咲智子 Kevin Deng <sxzz@sxzz.moe>
This commit is contained in:
parent
81c8a74748
commit
ba9a91a34e
7 changed files with 95 additions and 6 deletions
|
@ -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: {},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
36
composables/settings/wellness.ts
Normal file
36
composables/settings/wellness.ts
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue