Add foundational components and logic for migration, UI design, and input handling
- Introduced foundational UI components (`Badge`, `LockCard`, `SectionHeader`, `AvatarIcon`, etc.) for flexible layouts and consistent design. - Added migration support with the `MigrationModal` component and backend integration for exporting/importing data between Electron and Tauri. - Extended form components with `TextAreaInput`, `OrderInput`, `ToggleField`, and `ToolbarSelect` for improved input handling. - Updated `ScribeShell` with migration popup logic to prompt users for data migration. - Integrated `AlertStack` for better alert handling and notification management. - Enhanced Rust/Tauri services with migration command implementations. - Added translations and styles for new components.
This commit is contained in:
30
hooks/useTheme.ts
Normal file
30
hooks/useTheme.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import {useCallback, useEffect, useState} from "react";
|
||||
import {SupportedTheme} from "@/context/ThemeContext";
|
||||
import {getCookie, setCookie} from "@/lib/utils/cookies";
|
||||
|
||||
interface UseThemeReturn {
|
||||
theme: SupportedTheme;
|
||||
setTheme: (theme: SupportedTheme) => void;
|
||||
}
|
||||
|
||||
export default function useTheme(): UseThemeReturn {
|
||||
const [theme, setThemeState] = useState<SupportedTheme>('dark');
|
||||
|
||||
useEffect(function loadSavedTheme(): void {
|
||||
const savedTheme: string | null = getCookie('theme');
|
||||
if (savedTheme === 'light' || savedTheme === 'dark') {
|
||||
setThemeState(savedTheme);
|
||||
document.documentElement.setAttribute('data-theme', savedTheme);
|
||||
} else {
|
||||
document.documentElement.setAttribute('data-theme', 'dark');
|
||||
}
|
||||
}, []);
|
||||
|
||||
const setTheme = useCallback(function applyTheme(newTheme: SupportedTheme): void {
|
||||
setThemeState(newTheme);
|
||||
setCookie('theme', newTheme, 365);
|
||||
document.documentElement.setAttribute('data-theme', newTheme);
|
||||
}, []);
|
||||
|
||||
return {theme, setTheme};
|
||||
}
|
||||
Reference in New Issue
Block a user