diff --git a/src/components/GiscusComment.tsx b/src/components/GiscusComment.tsx index 26afe96..4a1d2eb 100644 --- a/src/components/GiscusComment.tsx +++ b/src/components/GiscusComment.tsx @@ -9,10 +9,33 @@ const GiscusComment = () => { const [theme, setTheme] = React.useState('preferred_color_scheme') React.useEffect(() => { + // Initial theme setup const savedTheme = localStorage.getItem('theme') if (savedTheme) { setTheme(savedTheme) } + + // Listen for theme changes + const handleThemeChange = (e: CustomEvent<{ theme: string }>) => { + setTheme(e.detail.theme) + } + + document.addEventListener('theme-change', handleThemeChange as EventListener) + + // Listen for astro:after-swap events (view transitions) + const handleAfterSwap = () => { + const currentTheme = localStorage.getItem('theme') + if (currentTheme) { + setTheme(currentTheme) + } + } + + document.addEventListener('astro:after-swap', handleAfterSwap) + + return () => { + document.removeEventListener('theme-change', handleThemeChange as EventListener) + document.removeEventListener('astro:after-swap', handleAfterSwap) + } }, []) return ( diff --git a/src/components/layout/Header.astro b/src/components/layout/Header.astro index facdae9..cee1dd5 100644 --- a/src/components/layout/Header.astro +++ b/src/components/layout/Header.astro @@ -3,9 +3,9 @@ import kazootttAvatar from '../../assets/kazoottt-avatar.jpeg' import { Image } from 'astro:assets' --- -
+