2026-09-13 21:02:25 +03:30
|
|
|
// Pinia replacement for the parts of legacy henza_admin/src/store/state.js +
|
|
|
|
|
// mutations.js that the app shell actually uses: window width, scroll position,
|
|
|
|
|
// and the active theme. The Vuexy customizer state (sidebar width, theme tour,
|
|
|
|
|
// footer type, ...) is carried in themeConfig.ts instead, as in legacy.
|
|
|
|
|
import { defineStore } from 'pinia';
|
|
|
|
|
import themeConfig, { type ThemeMode } from '../themeConfig';
|
|
|
|
|
|
2026-09-14 15:20:47 +03:30
|
|
|
const SIDEBAR_COLLAPSED_KEY = 'admin-panel:sidebarCollapsed';
|
|
|
|
|
|
|
|
|
|
/** Reads the persisted collapse state, falling back to themeConfig's default
|
|
|
|
|
* when localStorage is unavailable or has never been set. */
|
|
|
|
|
function readPersistedCollapsed(): boolean {
|
|
|
|
|
if (typeof window === 'undefined') return themeConfig.sidebarCollapsed;
|
|
|
|
|
try {
|
|
|
|
|
const raw = window.localStorage.getItem(SIDEBAR_COLLAPSED_KEY);
|
|
|
|
|
return raw === null ? themeConfig.sidebarCollapsed : raw === '1';
|
|
|
|
|
} catch {
|
|
|
|
|
return themeConfig.sidebarCollapsed;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-13 21:02:25 +03:30
|
|
|
export const useLayoutStore = defineStore('layout', {
|
|
|
|
|
state: () => ({
|
|
|
|
|
windowWidth: typeof window !== 'undefined' ? window.innerWidth : 0,
|
|
|
|
|
scrollY: 0,
|
|
|
|
|
theme: themeConfig.theme as ThemeMode,
|
|
|
|
|
// legacy state.js: sidebar visibility for the vertical nav menu
|
|
|
|
|
isSidebarActive: true,
|
2026-09-14 15:20:47 +03:30
|
|
|
sidebarCollapsed: readPersistedCollapsed(),
|
2026-09-13 21:02:25 +03:30
|
|
|
}),
|
|
|
|
|
getters: {
|
|
|
|
|
// legacy used breakpoints of 1200 (theme tour) and 992 (nav menu collapse)
|
|
|
|
|
isSmallScreen: (s) => s.windowWidth < 992,
|
|
|
|
|
},
|
|
|
|
|
actions: {
|
|
|
|
|
// legacy mutation: UPDATE_WINDOW_WIDTH
|
|
|
|
|
updateWindowWidth(width: number) {
|
|
|
|
|
this.windowWidth = width;
|
|
|
|
|
},
|
|
|
|
|
// legacy mutation: UPDATE_WINDOW_SCROLL_Y
|
|
|
|
|
updateWindowScrollY(y: number) {
|
|
|
|
|
this.scrollY = y;
|
|
|
|
|
},
|
|
|
|
|
toggleSidebar(value?: boolean) {
|
|
|
|
|
this.isSidebarActive = value ?? !this.isSidebarActive;
|
|
|
|
|
},
|
|
|
|
|
setSidebarCollapsed(value: boolean) {
|
|
|
|
|
this.sidebarCollapsed = value;
|
2026-09-14 15:20:47 +03:30
|
|
|
if (typeof window === 'undefined') return;
|
|
|
|
|
try {
|
|
|
|
|
window.localStorage.setItem(SIDEBAR_COLLAPSED_KEY, value ? '1' : '0');
|
|
|
|
|
} catch {
|
|
|
|
|
// localStorage unavailable (private mode, disabled site data, ...) —
|
|
|
|
|
// collapse state just won't persist across reloads.
|
|
|
|
|
}
|
2026-09-13 21:02:25 +03:30
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|