From 756c1fb3d69ca497b9467edb7502d97a62907e50 Mon Sep 17 00:00:00 2001 From: immobe Date: Sat, 21 Sep 2024 00:07:51 +0200 Subject: [PATCH] refactor: Remove ThemeToggle component and related theme management logic from Layout and index pages --- src/components/toggle-switch.tsx | 35 -------------------------------- src/hooks/use-is-scrolled.ts | 1 + src/layouts/Layout.astro | 27 ------------------------ src/pages/index.astro | 2 -- src/styles/utilities.css | 8 +++++--- 5 files changed, 6 insertions(+), 67 deletions(-) delete mode 100644 src/components/toggle-switch.tsx diff --git a/src/components/toggle-switch.tsx b/src/components/toggle-switch.tsx deleted file mode 100644 index fdf1f98..0000000 --- a/src/components/toggle-switch.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import type {FunctionalComponent} from 'preact'; -import {useEffect, useState} from 'preact/hooks'; - -const ThemeToggle: FunctionalComponent = () => { - const [theme, setTheme] = useState(localStorage.getItem('theme') ?? 'light'); - - const [isMounted, setIsMounted] = useState(false); - - useEffect(() => { - setIsMounted(true); - }, []); - - if (!isMounted) { - return null; - } - - const handleClick = () => { - setTheme(theme === 'light' ? 'dark' : 'light'); - }; - - useEffect(() => { - if (theme === 'dark') { - document.documentElement.classList.add('dark'); - } else { - document.documentElement.classList.remove('dark'); - } - localStorage.setItem('theme', theme); - }, [theme]); - - return ( - - ); -}; - -export default ThemeToggle; diff --git a/src/hooks/use-is-scrolled.ts b/src/hooks/use-is-scrolled.ts index 1e59b7e..db9d142 100644 --- a/src/hooks/use-is-scrolled.ts +++ b/src/hooks/use-is-scrolled.ts @@ -9,6 +9,7 @@ export function useIsScrolled(y = 0): boolean { }; window.addEventListener('scroll', handleScroll); + handleScroll(); return () => window.removeEventListener('scroll', handleScroll); }, [y]); diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index d5460e8..823dd76 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -10,33 +10,6 @@ import '../styles/utilities.css'; import Navbar from '../components/navbar'; --- - - {title} diff --git a/src/pages/index.astro b/src/pages/index.astro index 1080951..7c44e05 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,7 +1,6 @@ --- import Layout from '../layouts/Layout.astro'; import VideoWrapper from '../components/video-wrapper.tsx'; -import ThemeToggle from '../components/toggle-switch.tsx'; ---