You've already forked AstralRinth
forked from didirus/AstralRinth
* refactor(frontend): move Toggle component to Composition API + TS **Toggle.vue**: - Enable composition API and TS - Added `disabled` to props - Remove redundant `checked` - Replace `modelValue` and `emits` with `defineModel` compiler macro **Others**: - Replace emit handling and `model-value` with `v-model` where simple logic was used - Not `FeatureFlagSettings.vue` (contained custom code on receiving emit) - Not `Mods.vue` (contained custom code on receiving emit) - Remove redundant `checked` attribute * fix(app): toggles not updating value
44 lines
1.0 KiB
Vue
44 lines
1.0 KiB
Vue
<script setup lang="ts">
|
|
import { Toggle } from '@modrinth/ui'
|
|
import { useTheming } from '@/store/state'
|
|
import { ref, watch } from 'vue'
|
|
import { get, set } from '@/helpers/settings'
|
|
|
|
const themeStore = useTheming()
|
|
|
|
const settings = ref(await get())
|
|
const options = ref(['project_background', 'page_path'])
|
|
|
|
function getStoreValue(key: string) {
|
|
return themeStore.featureFlags[key] ?? false
|
|
}
|
|
|
|
function setStoreValue(key: string, value: boolean) {
|
|
themeStore.featureFlags[key] = value
|
|
settings.value.feature_flags[key] = value
|
|
}
|
|
|
|
watch(
|
|
settings,
|
|
async () => {
|
|
await set(settings.value)
|
|
},
|
|
{ deep: true },
|
|
)
|
|
</script>
|
|
<template>
|
|
<div v-for="option in options" :key="option" class="mt-4 flex items-center justify-between">
|
|
<div>
|
|
<h2 class="m-0 text-lg font-extrabold text-contrast capitalize">
|
|
{{ option }}
|
|
</h2>
|
|
</div>
|
|
|
|
<Toggle
|
|
id="advanced-rendering"
|
|
:model-value="getStoreValue(option)"
|
|
@update:model-value="() => setStoreValue(option, !themeStore.featureFlags[option])"
|
|
/>
|
|
</div>
|
|
</template>
|