mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-05 08:23:35 +00:00
Refactor AppProvider
This commit is contained in:
9 files changed
+156
-204
No files matched your search
@@ -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
@@ -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,
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user