From 7bfb31ea2f548f54d9a61fa983c67c1f78aae971 Mon Sep 17 00:00:00 2001 From: Francesco Sansalvadore Date: Tue, 16 Apr 2024 14:34:10 +0200 Subject: [PATCH] restore dark theme on unmount --- apps/www/pages/ga-week/index.tsx | 11 ++++++++--- apps/www/pages/ga-week/tickets/[username].tsx | 11 ++++++++--- apps/www/pages/ga.tsx | 10 +++++++--- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/apps/www/pages/ga-week/index.tsx b/apps/www/pages/ga-week/index.tsx index 76f899f804f..706f20c4fec 100644 --- a/apps/www/pages/ga-week/index.tsx +++ b/apps/www/pages/ga-week/index.tsx @@ -65,14 +65,19 @@ export default function GAWeekIndex({ meetups }: Props) { } }, [supabase]) + const isDark = resolvedTheme?.includes('dark') const isDarkTheme = resolvedTheme === 'dark' useEffect(() => { - if (isDarkTheme) { - setTheme('deep-dark') - } + isDarkTheme && setTheme('deep-dark') }, [isDarkTheme]) + useEffect(() => { + return () => { + isDark && setTheme('dark') + } + }, []) + useEffect(() => { if (session?.user) { if (userData?.id) { diff --git a/apps/www/pages/ga-week/tickets/[username].tsx b/apps/www/pages/ga-week/tickets/[username].tsx index 885f2ff229e..1e46d014e98 100644 --- a/apps/www/pages/ga-week/tickets/[username].tsx +++ b/apps/www/pages/ga-week/tickets/[username].tsx @@ -43,14 +43,19 @@ export default function UsernamePage({ user, ogImageUrl }: Props) { const [ticketState, setTicketState] = useState('ticket') const { resolvedTheme, setTheme } = useTheme() + const isDark = resolvedTheme?.includes('dark') const isDarkTheme = resolvedTheme === 'dark' useEffect(() => { - if (isDarkTheme) { - setTheme('deep-dark') - } + isDarkTheme && setTheme('deep-dark') }, [isDarkTheme]) + useEffect(() => { + return () => { + isDark && setTheme('dark') + } + }, []) + if (!ticketNumber) { return } diff --git a/apps/www/pages/ga.tsx b/apps/www/pages/ga.tsx index 9694737a166..48d367ff2eb 100644 --- a/apps/www/pages/ga.tsx +++ b/apps/www/pages/ga.tsx @@ -30,11 +30,15 @@ export default function IndexPage() { const isDarkTheme = resolvedTheme === 'dark' useEffect(() => { - if (isDarkTheme) { - setTheme('deep-dark') - } + isDarkTheme && setTheme('deep-dark') }, [isDarkTheme]) + useEffect(() => { + return () => { + isDark && setTheme('dark') + } + }, []) + return (