Files
carmanagement/apps/homepage/src/components/app-shell/ThemeController.tsx
T
root d7fb7b7a7b
Build & Deploy / Build & Push Docker Image (push) Failing after 47s
Build & Deploy / Deploy to VPS (push) Has been skipped
Test / API Unit Tests (push) Failing after 5m4s
Test / Marketplace Unit Tests (push) Failing after 4m55s
Test / Admin Unit Tests (push) Successful in 9m37s
Test / Dashboard Unit Tests (push) Successful in 9m37s
Test / API Integration Tests (push) Successful in 9m54s
redesign the homepage
2026-06-26 16:27:21 -04:00

32 lines
1017 B
TypeScript

'use client';
import { applyTheme, currentThemePreference } from '@/lib/theme/client';
import { themeStorageKey } from '@/lib/theme/config';
import { useEffect } from 'react';
export function ThemeController() {
useEffect(() => {
const media = window.matchMedia('(prefers-color-scheme: dark)');
const handleSystemChange = () => {
if (currentThemePreference() === 'system') applyTheme('system');
};
const handleStorage = (event: StorageEvent) => {
if (event.key === themeStorageKey && event.newValue) {
const preference = event.newValue;
if (preference === 'light' || preference === 'dark' || preference === 'system') {
applyTheme(preference);
}
}
};
media.addEventListener('change', handleSystemChange);
window.addEventListener('storage', handleStorage);
return () => {
media.removeEventListener('change', handleSystemChange);
window.removeEventListener('storage', handleStorage);
};
}, []);
return null;
}