Refactor AppProvider

This commit is contained in:
Alex Gleason committed 2025-06-04 10:06:38 -05:00
1 parent c3310ab485
commit 3ad83cd114
9 files changed
+156 -204

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
import { useContext } from "react";
import { AppContext, type AppContextType } from "@/contexts/AppContext";
/**
* Hook to access and update application configuration
* @returns Application context with config and update methods
*/
export function useAppConfig(): AppContextType {
const context = useContext(AppContext);
if (context === undefined) {
throw new Error('useAppConfig must be used within an AppProvider');
}
return context;
}
+18 -4
View File
@@ -1,6 +1,20 @@
import { useTheme as useThemeFromProvider } from "@/components/AppProvider";
import { type Theme } from "@/contexts/AppContext";
import { useAppConfig } from "@/hooks/useAppConfig";
/** Hook to get and set the active theme. */
export function useTheme() {
return useThemeFromProvider();
/**
* Hook to get and set the active theme
* @returns Theme context with theme and setTheme
*/
export function useTheme(): { theme: Theme; setTheme: (theme: Theme) => void } {
const { config, updateConfig } = useAppConfig();
return {
theme: config.theme,
setTheme: (theme: Theme) => {
updateConfig((currentConfig) => ({
...currentConfig,
theme,
}));
}
}
}