Refresh user preferences from back-end when entering the Options view

This commit is contained in:
Bubka
2024-02-18 14:58:21 +01:00
parent f2d4c43239
commit 300d3c3dc8
4 changed files with 28 additions and 2 deletions

View File

@ -1,5 +1,6 @@
import { defineStore } from 'pinia'
import authService from '@/services/authService'
import userService from '@/services/userService'
import router from '@/router'
import { useColorMode } from '@vueuse/core'
import { useTwofaccounts } from '@/stores/twofaccounts'
@ -108,7 +109,6 @@ export const useUserStore = defineStore({
mode.value = this.preferences.theme == 'system' ? 'auto' : this.preferences.theme
},
/**
* Applies user language
*/
@ -121,13 +121,27 @@ export const useUserStore = defineStore({
else loadLanguageAsync('en')
},
/**
* Applies both user theme & language
*/
applyUserPrefs() {
this.applyTheme()
this.applyLanguage()
},
/**
* Refresh user preferences with backend state
*/
refreshPreferences() {
userService.getPreferences({returnError: true})
.then(response => {
response.data.forEach(preference => {
this.preferences[preference.key] = preference.value
})
})
.catch(error => {
notify.alert({ text: trans('errors.data_cannot_be_refreshed_from_server') })
})
}
},