mirror of
https://github.com/elk-zone/elk
synced 2024-12-15 15:18:00 +09:00
ba9a91a34e
Co-authored-by: 三咲智子 Kevin Deng <sxzz@sxzz.moe>
37 lines
1.0 KiB
TypeScript
37 lines
1.0 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
|
|
}
|