20 lines
884 B
TypeScript
20 lines
884 B
TypeScript
import { defineStore } from 'pinia'
|
|
import { computed, ref, watch } from 'vue'
|
|
import { useAuth } from './auth'
|
|
|
|
export type Edition = 'common' | 'advanced'
|
|
export const useEdition = defineStore('edition', () => {
|
|
const auth = useAuth(), mode = ref<Edition>('common')
|
|
const key = () => `vdi.console-mode:${auth.user?.id || ''}`
|
|
watch(() => auth.user?.id, id => {
|
|
mode.value = 'common'
|
|
if (id) { try { if (localStorage.getItem(key()) === 'advanced') mode.value = 'advanced' } catch { /* Storage can be unavailable. */ } }
|
|
}, { immediate: true, flush: 'sync' })
|
|
function select(value: Edition) {
|
|
mode.value = value
|
|
if (auth.user) { try { localStorage.setItem(key(), value) } catch { /* Navigation still works without persistence. */ } }
|
|
}
|
|
const home = computed(() => mode.value === 'common' ? '/workbench' : '/overview')
|
|
return { mode, home, select }
|
|
})
|