Refactor routing in App component to enhance navigation and improve error handling by integrating dynamic routes and updating the NotFound route.

This commit is contained in:
becarta
2025-05-23 12:43:00 +02:00
parent f40db0f5c9
commit a544759a3b
11127 changed files with 1647032 additions and 0 deletions

47
src/utils/theme.ts Normal file
View File

@@ -0,0 +1,47 @@
export type Theme = 'light' | 'dark';
export function getThemePreference(): Theme {
if (typeof localStorage !== 'undefined' && localStorage.getItem('theme')) {
return localStorage.getItem('theme') as Theme;
}
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
}
export function isDark() {
return getThemePreference() === 'dark';
}
export function setTheme(theme: Theme) {
localStorage.setItem('theme', theme);
reflectPreference(theme);
}
export function reflectPreference(theme: Theme) {
document.documentElement.setAttribute('data-theme', theme);
const themeColorMeta = document.querySelector('meta[name="theme-color"]');
if (themeColorMeta) {
themeColorMeta.setAttribute('content', theme === 'dark' ? '#0f172a' : '#ffffff');
}
}
// Initialize theme on page load
export function initTheme() {
const theme = getThemePreference();
reflectPreference(theme);
// Listen for system theme changes
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
if (!localStorage.getItem('theme')) {
reflectPreference(e.matches ? 'dark' : 'light');
}
});
}
// Toggle theme function
export function toggleTheme() {
const currentTheme = getThemePreference();
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
setTheme(newTheme);
return newTheme;
}