Files
panel/resources/js/@core/stores/config.js
2025-08-04 16:33:07 +03:30

64 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { storeToRefs } from 'pinia'
import { useTheme } from 'vuetify'
import { cookieRef, useLayoutConfigStore } from '@layouts/stores/config'
import { themeConfig } from '@themeConfig'
// SECTION Store
export const useConfigStore = defineStore('config', () => {
// 👉 Theme
const userPreferredColorScheme = usePreferredColorScheme()
const cookieColorScheme = cookieRef('color-scheme', 'light')
watch(userPreferredColorScheme, val => {
if (val !== 'no-preference')
cookieColorScheme.value = val
}, { immediate: true })
const theme = cookieRef('theme', themeConfig.app.theme)
// 👉 isVerticalNavSemiDark
const isVerticalNavSemiDark = cookieRef('isVerticalNavSemiDark', themeConfig.verticalNav.isVerticalNavSemiDark)
// 👉 isVerticalNavSemiDark
const skin = cookieRef('skin', themeConfig.app.skin)
// We need to use `storeToRefs` to forward the state
const { isLessThanOverlayNavBreakpoint, appContentWidth, navbarType, isNavbarBlurEnabled, appContentLayoutNav, isVerticalNavCollapsed, footerType, isAppRTL } = storeToRefs(useLayoutConfigStore())
return {
theme,
isVerticalNavSemiDark,
skin,
// @layouts exports
isLessThanOverlayNavBreakpoint,
appContentWidth,
navbarType,
isNavbarBlurEnabled,
appContentLayoutNav,
isVerticalNavCollapsed,
footerType,
isAppRTL,
}
})
// !SECTION
// SECTION Init
export const initConfigStore = () => {
const userPreferredColorScheme = usePreferredColorScheme()
const vuetifyTheme = useTheme()
const configStore = useConfigStore()
watch([() => configStore.theme, userPreferredColorScheme], () => {
vuetifyTheme.global.name.value = configStore.theme === 'system'
? userPreferredColorScheme.value === 'dark'
? 'dark'
: 'light'
: configStore.theme
})
onMounted(() => {
if (configStore.theme === 'system')
vuetifyTheme.global.name.value = userPreferredColorScheme.value
})
}
// !SECTION