feat(user): migrate color scheme settings to persistance in db
This commit is contained in:
parent
4b0022664a
commit
5325f6d7d9
@ -1,6 +1,7 @@
|
|||||||
import {computed, watch, readonly} from 'vue'
|
import {computed, watch, readonly} from 'vue'
|
||||||
import {useStorage, createSharedComposable, usePreferredColorScheme, tryOnMounted} from '@vueuse/core'
|
import {createSharedComposable, usePreferredColorScheme, tryOnMounted} from '@vueuse/core'
|
||||||
import type {BasicColorSchema} from '@vueuse/core'
|
import type {BasicColorSchema} from '@vueuse/core'
|
||||||
|
import {useAuthStore} from '@/stores/auth'
|
||||||
|
|
||||||
const STORAGE_KEY = 'color-scheme'
|
const STORAGE_KEY = 'color-scheme'
|
||||||
|
|
||||||
@ -17,7 +18,8 @@ const CLASS_LIGHT = 'light'
|
|||||||
// - value is synced via `createSharedComposable`
|
// - value is synced via `createSharedComposable`
|
||||||
// https://github.com/vueuse/vueuse/blob/main/packages/core/useDark/index.ts
|
// https://github.com/vueuse/vueuse/blob/main/packages/core/useDark/index.ts
|
||||||
export const useColorScheme = createSharedComposable(() => {
|
export const useColorScheme = createSharedComposable(() => {
|
||||||
const store = useStorage<BasicColorSchema>(STORAGE_KEY, DEFAULT_COLOR_SCHEME_SETTING)
|
const authStore = useAuthStore()
|
||||||
|
const store = computed(() => authStore.settings.frontendSettings.colorSchema)
|
||||||
|
|
||||||
const preferredColorScheme = usePreferredColorScheme()
|
const preferredColorScheme = usePreferredColorScheme()
|
||||||
|
|
||||||
|
@ -2,10 +2,12 @@
|
|||||||
import type {IAbstract} from './IAbstract'
|
import type {IAbstract} from './IAbstract'
|
||||||
import type {IProject} from './IProject'
|
import type {IProject} from './IProject'
|
||||||
import type {PrefixMode} from '@/modules/parseTaskText'
|
import type {PrefixMode} from '@/modules/parseTaskText'
|
||||||
|
import type {BasicColorSchema} from '@vueuse/core'
|
||||||
|
|
||||||
export interface IFrontendSettings {
|
export interface IFrontendSettings {
|
||||||
playSoundWhenDone: boolean
|
playSoundWhenDone: boolean
|
||||||
quickAddMagicMode: PrefixMode
|
quickAddMagicMode: PrefixMode
|
||||||
|
colorSchema: BasicColorSchema
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IUserSettings extends IAbstract {
|
export interface IUserSettings extends IAbstract {
|
||||||
|
@ -18,6 +18,7 @@ export default class UserSettingsModel extends AbstractModel<IUserSettings> impl
|
|||||||
frontendSettings: IFrontendSettings = {
|
frontendSettings: IFrontendSettings = {
|
||||||
playSoundWhenDone: true,
|
playSoundWhenDone: true,
|
||||||
quickAddMagicMode: PrefixMode.Default,
|
quickAddMagicMode: PrefixMode.Default,
|
||||||
|
colorSchema: 'auto'
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(data: Partial<IUserSettings> = {}) {
|
constructor(data: Partial<IUserSettings> = {}) {
|
||||||
|
@ -94,12 +94,14 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
settings.value = new UserSettingsModel({
|
settings.value = new UserSettingsModel({
|
||||||
...newSettings,
|
...newSettings,
|
||||||
frontendSettings: {
|
frontendSettings: {
|
||||||
...newSettings.frontendSettings,
|
|
||||||
// Need to set default settings here in case the user does not have any saved in the api already
|
// Need to set default settings here in case the user does not have any saved in the api already
|
||||||
|
playSoundWhenDone: true,
|
||||||
quickAddMagicMode: PrefixMode.Default,
|
quickAddMagicMode: PrefixMode.Default,
|
||||||
|
colorSchema: 'auto',
|
||||||
|
...newSettings.frontendSettings,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
console.log(settings.value.frontendSettings)
|
console.log('settings from auth store', {...settings.value.frontendSettings})
|
||||||
}
|
}
|
||||||
|
|
||||||
function setAuthenticated(newAuthenticated: boolean) {
|
function setAuthenticated(newAuthenticated: boolean) {
|
||||||
|
@ -111,7 +111,7 @@
|
|||||||
{{ $t('user.settings.appearance.title') }}
|
{{ $t('user.settings.appearance.title') }}
|
||||||
</span>
|
</span>
|
||||||
<div class="select ml-2">
|
<div class="select ml-2">
|
||||||
<select v-model="activeColorSchemeSetting">
|
<select v-model="settings.frontendSettings.colorSchema">
|
||||||
<!-- TODO: use the Vikunja logo in color scheme as option buttons -->
|
<!-- TODO: use the Vikunja logo in color scheme as option buttons -->
|
||||||
<option v-for="(title, schemeId) in colorSchemeSettings" :key="schemeId" :value="schemeId">
|
<option v-for="(title, schemeId) in colorSchemeSettings" :key="schemeId" :value="schemeId">
|
||||||
{{ title }}
|
{{ title }}
|
||||||
@ -161,10 +161,8 @@ import ProjectSearch from '@/components/tasks/partials/projectSearch.vue'
|
|||||||
import {SUPPORTED_LOCALES} from '@/i18n'
|
import {SUPPORTED_LOCALES} from '@/i18n'
|
||||||
import {playSoundWhenDoneKey, playPopSound} from '@/helpers/playPop'
|
import {playSoundWhenDoneKey, playPopSound} from '@/helpers/playPop'
|
||||||
import {createRandomID} from '@/helpers/randomId'
|
import {createRandomID} from '@/helpers/randomId'
|
||||||
import {success} from '@/message'
|
|
||||||
import {AuthenticatedHTTPFactory} from '@/helpers/fetcher'
|
import {AuthenticatedHTTPFactory} from '@/helpers/fetcher'
|
||||||
|
|
||||||
import {useColorScheme} from '@/composables/useColorScheme'
|
|
||||||
import {useTitle} from '@/composables/useTitle'
|
import {useTitle} from '@/composables/useTitle'
|
||||||
|
|
||||||
import {useProjectStore} from '@/stores/projects'
|
import {useProjectStore} from '@/stores/projects'
|
||||||
@ -176,31 +174,12 @@ useTitle(() => `${t('user.settings.general.title')} - ${t('user.settings.title')
|
|||||||
|
|
||||||
const DEFAULT_PROJECT_ID = 0
|
const DEFAULT_PROJECT_ID = 0
|
||||||
|
|
||||||
function useColorSchemeSetting() {
|
|
||||||
const {t} = useI18n({useScope: 'global'})
|
|
||||||
const colorSchemeSettings = computed(() => ({
|
const colorSchemeSettings = computed(() => ({
|
||||||
light: t('user.settings.appearance.colorScheme.light'),
|
light: t('user.settings.appearance.colorScheme.light'),
|
||||||
auto: t('user.settings.appearance.colorScheme.system'),
|
auto: t('user.settings.appearance.colorScheme.system'),
|
||||||
dark: t('user.settings.appearance.colorScheme.dark'),
|
dark: t('user.settings.appearance.colorScheme.dark'),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const {store} = useColorScheme()
|
|
||||||
watch(store, (schemeId) => {
|
|
||||||
success({
|
|
||||||
message: t('user.settings.appearance.setSuccess', {
|
|
||||||
colorScheme: colorSchemeSettings.value[schemeId],
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
|
||||||
colorSchemeSettings,
|
|
||||||
activeColorSchemeSetting: store,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const {colorSchemeSettings, activeColorSchemeSetting} = useColorSchemeSetting()
|
|
||||||
|
|
||||||
function useAvailableTimezones() {
|
function useAvailableTimezones() {
|
||||||
const availableTimezones = ref([])
|
const availableTimezones = ref([])
|
||||||
|
|
||||||
@ -222,7 +201,7 @@ const settings = ref<IUserSettings>({
|
|||||||
// Sub objects get exported as read only as well, so we need to
|
// Sub objects get exported as read only as well, so we need to
|
||||||
// explicitly spread the object here to allow modification
|
// explicitly spread the object here to allow modification
|
||||||
...authStore.settings.frontendSettings,
|
...authStore.settings.frontendSettings,
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
const id = ref(createRandomID())
|
const id = ref(createRandomID())
|
||||||
const availableLanguageOptions = ref(
|
const availableLanguageOptions = ref(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user