Add UI settings API and improve context initialization

- Add /settings/ui GET and PUT endpoints for UI settings
- Improve ThemeContext with better initialization and auto accent handling
- Update SidebarContext with expanded state persistence
- Fix context initialization in ModulesContext and ViewModeContext
- Update components to use improved theme/sidebar contexts

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-14 19:50:30 +01:00
parent 0608217702
commit 41c41adb98
10 changed files with 163 additions and 52 deletions

View File

@@ -1,6 +1,7 @@
import { createContext, useContext, useState, useEffect, useCallback } from 'react';
import type { ReactNode } from 'react';
import { settingsAPI } from '../api/client';
import { useAuth } from './AuthContext';
import type { UserPermissions } from '../types';
// User-facing modules that can be toggled
@@ -39,6 +40,7 @@ const getDefaultStates = (): Record<ModuleId, ModuleState> => {
};
export function ModulesProvider({ children }: { children: ReactNode }) {
const { token } = useAuth();
const [moduleStates, setModuleStates] = useState<Record<ModuleId, ModuleState>>(getDefaultStates);
const [isLoading, setIsLoading] = useState(true);
const [hasInitialized, setHasInitialized] = useState(false);
@@ -110,16 +112,18 @@ export function ModulesProvider({ children }: { children: ReactNode }) {
}
}, [moduleStates]);
// Load modules on mount when token exists
// Load modules when token becomes available
useEffect(() => {
const token = localStorage.getItem('token');
if (token) {
setIsLoading(true);
setHasInitialized(false);
loadModulesFromBackend();
} else {
setModuleStates(getDefaultStates());
setIsLoading(false);
setHasInitialized(true); // No token, mark as initialized
}
}, [loadModulesFromBackend]);
}, [token, loadModulesFromBackend]);
const isModuleEnabled = useCallback((moduleId: string): boolean => {
// Dashboard is always enabled