theming, date, time localisation, additional features, seeding initial cleanup

This commit is contained in:
mikicvi
2025-09-26 21:12:59 +01:00
parent b89d91ade2
commit 22c462c61c
43 changed files with 2647 additions and 550 deletions
+47
View File
@@ -7,3 +7,50 @@ import { type ThemeProviderProps } from 'next-themes/dist/types';
export function ThemeProvider({ children, ...props }: ThemeProviderProps) {
return <NextThemesProvider {...props}>{children}</NextThemesProvider>;
}
// Enhanced hook for theme management with database sync
export function useThemeWithSync() {
const [mounted, setMounted] = React.useState(false);
const [userTheme, setUserTheme] = React.useState<'light' | 'dark' | 'system'>('system');
React.useEffect(() => {
setMounted(true);
fetchUserTheme();
}, []);
const fetchUserTheme = async () => {
try {
const response = await fetch('/api/users/theme');
if (response.ok) {
const data = await response.json();
setUserTheme(data.themePreference);
}
} catch (error) {
console.error('Failed to fetch user theme preference:', error);
}
};
const updateTheme = async (theme: 'light' | 'dark' | 'system') => {
try {
const response = await fetch('/api/users/theme', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ themePreference: theme }),
});
if (response.ok) {
setUserTheme(theme);
}
} catch (error) {
console.error('Failed to update theme preference:', error);
}
};
return {
mounted,
theme: userTheme,
setTheme: updateTheme,
};
}