mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-07 16:34:26 +00:00
Refactor workspace context usage to improve structure and introduce ThemeContext
This commit is contained in:
39
app/src/hooks/useWorkspace.ts
Normal file
39
app/src/hooks/useWorkspace.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { useWorkspaceData } from '../contexts/WorkspaceDataContext';
|
||||
import { useTheme } from '../contexts/ThemeContext';
|
||||
import { useWorkspaceOperations } from './useWorkspaceOperations';
|
||||
import type { Workspace } from '@/types/models';
|
||||
import type { MantineColorScheme } from '@mantine/core';
|
||||
|
||||
interface UseWorkspaceResult {
|
||||
currentWorkspace: Workspace | null;
|
||||
workspaces: Workspace[];
|
||||
settings:
|
||||
| Workspace
|
||||
| typeof import('@/types/models').DEFAULT_WORKSPACE_SETTINGS;
|
||||
updateSettings: (newSettings: Partial<Workspace>) => Promise<void>;
|
||||
loading: boolean;
|
||||
colorScheme: MantineColorScheme;
|
||||
updateColorScheme: (newTheme: MantineColorScheme) => void;
|
||||
switchWorkspace: (workspaceName: string) => Promise<void>;
|
||||
deleteCurrentWorkspace: () => Promise<void>;
|
||||
}
|
||||
|
||||
export const useWorkspace = (): UseWorkspaceResult => {
|
||||
const { currentWorkspace, workspaces, settings, loading } =
|
||||
useWorkspaceData();
|
||||
const { colorScheme, updateColorScheme } = useTheme();
|
||||
const { switchWorkspace, deleteCurrentWorkspace, updateSettings } =
|
||||
useWorkspaceOperations();
|
||||
|
||||
return {
|
||||
currentWorkspace,
|
||||
workspaces,
|
||||
settings,
|
||||
updateSettings,
|
||||
loading,
|
||||
colorScheme,
|
||||
updateColorScheme,
|
||||
switchWorkspace,
|
||||
deleteCurrentWorkspace,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user