2020-08-28 18:54:18 +02:00
|
|
|
/**
|
|
|
|
* Settings module store.
|
|
|
|
* @module store/settings
|
|
|
|
*/
|
|
|
|
|
|
|
|
import i18n from '@/i18n'
|
2020-08-29 14:16:59 +02:00
|
|
|
import { loadLocaleMessages, updateDocumentLocale, loadDateFnsLocale } from '@/i18n/helpers'
|
2020-09-13 17:35:32 +02:00
|
|
|
import supportedLocales from '@/i18n/supportedLocales'
|
2020-08-28 18:54:18 +02:00
|
|
|
|
|
|
|
export default {
|
|
|
|
state: {
|
2020-08-29 14:16:59 +02:00
|
|
|
locale: localStorage.getItem('locale'),
|
2020-09-13 17:35:32 +02:00
|
|
|
fallbackLocale: localStorage.getItem('fallbackLocale'),
|
|
|
|
cache: localStorage.getItem('cache') !== 'false',
|
2020-10-08 23:58:09 +02:00
|
|
|
transitions: localStorage.getItem('transitions') !== 'false',
|
2022-10-26 15:36:25 +02:00
|
|
|
theme: localStorage.getItem('theme') === 'true',
|
2020-10-08 15:15:44 +02:00
|
|
|
experimental: localStorage.getItem('experimental') === 'true',
|
2020-12-16 15:09:19 +01:00
|
|
|
spinner: 'pacman',
|
2020-09-13 17:35:32 +02:00
|
|
|
supportedLocales: supportedLocales
|
2020-08-28 18:54:18 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
mutations: {
|
|
|
|
'SET_LOCALE' (state, locale) {
|
|
|
|
localStorage.setItem('locale', locale)
|
|
|
|
state.locale = locale
|
|
|
|
},
|
|
|
|
|
2020-11-01 17:03:06 +01:00
|
|
|
'SET_FALLBACKLOCALE' (state, locale) {
|
2020-08-28 18:54:18 +02:00
|
|
|
localStorage.setItem('fallbackLocale', locale)
|
|
|
|
state.fallbackLocale = locale
|
2020-09-13 17:35:32 +02:00
|
|
|
},
|
|
|
|
|
2020-10-08 15:15:44 +02:00
|
|
|
'SET_CACHE' (state, boolean) {
|
|
|
|
localStorage.setItem('cache', boolean)
|
|
|
|
state.cache = boolean
|
|
|
|
},
|
|
|
|
|
2020-10-08 23:58:09 +02:00
|
|
|
'SET_TRANSITIONS' (state, boolean) {
|
|
|
|
localStorage.setItem('transitions', boolean)
|
|
|
|
state.transitions = boolean
|
|
|
|
},
|
|
|
|
|
2020-10-08 15:15:44 +02:00
|
|
|
'SET_EXPERIMENTAL' (state, boolean) {
|
|
|
|
localStorage.setItem('experimental', boolean)
|
|
|
|
state.experimental = boolean
|
2020-12-16 15:09:19 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
'SET_SPINNER' (state, spinner) {
|
|
|
|
state.spinner = spinner
|
2022-09-02 13:46:21 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
'SET_THEME' (state, boolean) {
|
|
|
|
localStorage.setItem('theme', boolean)
|
|
|
|
state.theme = boolean
|
2022-09-06 11:44:55 +02:00
|
|
|
document.documentElement.setAttribute('dark-theme', boolean)
|
2020-08-28 18:54:18 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
'UPDATE_LOCALE' ({ commit }, locale) {
|
|
|
|
loadLocaleMessages(locale).then(() => {
|
|
|
|
updateDocumentLocale(locale)
|
|
|
|
commit('SET_LOCALE', locale)
|
2020-08-29 14:16:59 +02:00
|
|
|
i18n.locale = locale
|
2020-08-28 18:54:18 +02:00
|
|
|
})
|
2020-08-29 14:16:59 +02:00
|
|
|
// also query the date-fns locale object for filters
|
|
|
|
loadDateFnsLocale(locale)
|
2020-08-28 18:54:18 +02:00
|
|
|
},
|
|
|
|
|
2020-11-01 17:03:06 +01:00
|
|
|
'UPDATE_FALLBACKLOCALE' ({ commit }, locale) {
|
2020-08-28 18:54:18 +02:00
|
|
|
loadLocaleMessages(locale).then(() => {
|
2020-11-01 17:03:06 +01:00
|
|
|
commit('SET_FALLBACKLOCALE', locale)
|
2020-08-29 14:16:59 +02:00
|
|
|
i18n.fallbackLocale = [locale, 'en']
|
2020-08-28 18:54:18 +02:00
|
|
|
})
|
2022-09-02 13:46:21 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
'UPDATE_THEME' ({ commit }, theme) {
|
|
|
|
commit('SET_THEME', theme)
|
2020-08-28 18:54:18 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
getters: {
|
|
|
|
locale: state => (state.locale),
|
2020-09-13 17:35:32 +02:00
|
|
|
fallbackLocale: state => (state.fallbackLocale),
|
|
|
|
cache: state => (state.cache),
|
2020-10-08 23:58:09 +02:00
|
|
|
transitions: state => (state.transitions),
|
2022-09-02 13:46:21 +02:00
|
|
|
theme: state => (state.theme),
|
2020-10-08 15:15:44 +02:00
|
|
|
experimental: state => state.experimental,
|
2020-12-16 15:09:19 +01:00
|
|
|
spinner: state => state.spinner,
|
2020-09-13 17:35:32 +02:00
|
|
|
|
|
|
|
availableLocales: state => {
|
|
|
|
return Object.entries(state.supportedLocales).map(([locale, { name }]) => {
|
|
|
|
return { value: locale, text: name }
|
|
|
|
})
|
|
|
|
}
|
2020-08-28 18:54:18 +02:00
|
|
|
}
|
|
|
|
}
|