1
0
Fork 1
mirror of https://github.com/elk-zone/elk.git synced 2024-11-04 16:09:59 +00:00
elk/composables/settings/wellness.ts
wheat ba9a91a34e
feat: wellness settings (#927)
Co-authored-by: 三咲智子 Kevin Deng <sxzz@sxzz.moe>
2023-01-10 22:45:17 +08:00

37 lines
1 KiB
TypeScript

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
}