From bf00d37b4af799130e3dd8cd2c083ec933833281 Mon Sep 17 00:00:00 2001 From: c0mrade Date: Wed, 4 Feb 2026 12:31:32 +0300 Subject: [PATCH] fix: add theme toggle to desktop header and sync theme across components Add sun/moon toggle button to the desktop navigation bar so theme switching is available in web version. Sync theme state across multiple useTheme() instances via custom DOM event to avoid requiring page reload. --- src/components/layout/AppShell/AppShell.tsx | 55 +++++++++++++++++++++ src/hooks/useTheme.ts | 16 +++++- 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/src/components/layout/AppShell/AppShell.tsx b/src/components/layout/AppShell/AppShell.tsx index bb8f401..7b4bf61 100644 --- a/src/components/layout/AppShell/AppShell.tsx +++ b/src/components/layout/AppShell/AppShell.tsx @@ -6,6 +6,8 @@ import { useTranslation } from 'react-i18next'; import { useAuthStore } from '@/store/auth'; import { useBackButton, useHaptic } from '@/platform'; import { useTelegramSDK } from '@/hooks/useTelegramSDK'; +import { useTheme } from '@/hooks/useTheme'; +import { themeColorsApi } from '@/api/themeColors'; import { referralApi } from '@/api/referral'; import { wheelApi } from '@/api/wheel'; import { contestsApi } from '@/api/contests'; @@ -142,6 +144,38 @@ const LogoutIcon = ({ className }: { className?: string }) => ( ); +const SunIcon = ({ className }: { className?: string }) => ( + + + +); + +const MoonIcon = ({ className }: { className?: string }) => ( + + + +); + const FALLBACK_NAME = import.meta.env.VITE_APP_NAME || 'Cabinet'; const FALLBACK_LOGO = import.meta.env.VITE_APP_LOGO || 'V'; @@ -164,6 +198,15 @@ export function AppShell({ children }: AppShellProps) { isMobile, } = useTelegramSDK(); const haptic = useHaptic(); + const { toggleTheme, isDark } = useTheme(); + + // Theme toggle visibility + const { data: enabledThemes } = useQuery({ + queryKey: ['enabled-themes'], + queryFn: themeColorsApi.getEnabledThemes, + staleTime: 1000 * 60 * 5, + }); + const canToggleTheme = enabledThemes?.dark && enabledThemes?.light; // Only apply fullscreen UI adjustments on mobile Telegram (iOS/Android) const isMobileFullscreen = isFullscreen && isMobile; @@ -460,6 +503,18 @@ export function AppShell({ children }: AppShellProps) { {/* Right side actions */}
+ {canToggleTheme && ( + + )}