mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-15 17:24:10 +00:00
Create the complete TypeScript foundation for the Vue 3 migration in a parallel scripts-v2/ directory. 72 files, 5430 lines, zero any types, strict mode. - types/ (21 files): Domain interfaces for all 17 entities derived from actual Laravel models and API resources. Enums for all statuses. Generic API response wrappers. - api/ (29 files): Typed axios client with interceptors, endpoint constants from routes/api.php, 25 typed service classes covering every API endpoint. - composables/ (14 files): Vue 3 composition functions for auth, notifications, dialogs, modals, pagination, filters, currency, dates, theme, sidebar, company context, and permissions. - utils/ (5 files): Pure typed utilities for money formatting, date formatting (date-fns), localStorage, and error handling. - config/ (3 files): Typed ability constants, app constants. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
import { ref } from 'vue'
|
|
import type { Ref } from 'vue'
|
|
import * as ls from '../utils/local-storage'
|
|
import { LS_KEYS } from '../config/constants'
|
|
|
|
export interface UseSidebarReturn {
|
|
isCollapsed: Ref<boolean>
|
|
isSidebarOpen: Ref<boolean>
|
|
toggleCollapse: () => void
|
|
setSidebarVisibility: (visible: boolean) => void
|
|
}
|
|
|
|
const isCollapsed = ref<boolean>(
|
|
ls.get<string>(LS_KEYS.SIDEBAR_COLLAPSED) === 'true'
|
|
)
|
|
|
|
const isSidebarOpen = ref<boolean>(false)
|
|
|
|
/**
|
|
* Composable for managing sidebar state.
|
|
* Handles both the mobile sidebar open/close and the desktop collapsed toggle.
|
|
* Persists the collapsed state to localStorage.
|
|
*/
|
|
export function useSidebar(): UseSidebarReturn {
|
|
/**
|
|
* Toggle the sidebar collapsed/expanded state (desktop).
|
|
* Persists the new value to localStorage.
|
|
*/
|
|
function toggleCollapse(): void {
|
|
isCollapsed.value = !isCollapsed.value
|
|
ls.set(LS_KEYS.SIDEBAR_COLLAPSED, isCollapsed.value ? 'true' : 'false')
|
|
}
|
|
|
|
/**
|
|
* Set the mobile sidebar visibility.
|
|
*
|
|
* @param visible - Whether the sidebar should be visible
|
|
*/
|
|
function setSidebarVisibility(visible: boolean): void {
|
|
isSidebarOpen.value = visible
|
|
}
|
|
|
|
return {
|
|
isCollapsed,
|
|
isSidebarOpen,
|
|
toggleCollapse,
|
|
setSidebarVisibility,
|
|
}
|
|
}
|