Skip to content

Commit

Permalink
refactor: Remove ThemeToggle component and related theme management l…
Browse files Browse the repository at this point in the history
…ogic from Layout and index pages
  • Loading branch information
Immo-Be committed Sep 20, 2024
1 parent 833476f commit 756c1fb
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 67 deletions.
35 changes: 0 additions & 35 deletions src/components/toggle-switch.tsx

This file was deleted.

1 change: 1 addition & 0 deletions src/hooks/use-is-scrolled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export function useIsScrolled(y = 0): boolean {
};

window.addEventListener('scroll', handleScroll);
handleScroll();
return () => window.removeEventListener('scroll', handleScroll);
}, [y]);

Expand Down
27 changes: 0 additions & 27 deletions src/layouts/Layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,6 @@ import '../styles/utilities.css';
import Navbar from '../components/navbar';
---

<script>
import {THEME} from '../types/app';
const theme = (): THEME => {
if (typeof localStorage !== 'undefined' && localStorage.getItem('theme')) {
return localStorage.getItem('theme') as THEME;
}
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
return THEME.DARK;
}
return THEME.LIGHT;
};

const setTheme = () => {
if (theme() === THEME.LIGHT) {
document.documentElement.classList.remove(THEME.DARK);
} else {
document.documentElement.classList.add(THEME.DARK);
}
window.localStorage.setItem('theme', theme());
};

setTheme();
document.addEventListener('astro:after-swap', () => {
setTheme();
});
</script>

<html lang="de">
<head>
<title>{title}</title>
Expand Down
2 changes: 0 additions & 2 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
import Layout from '../layouts/Layout.astro';
import VideoWrapper from '../components/video-wrapper.tsx';
import ThemeToggle from '../components/toggle-switch.tsx';
---

<script>
Expand Down Expand Up @@ -102,6 +101,5 @@ import ThemeToggle from '../components/toggle-switch.tsx';
quas nisi iste quae! Id, impedit quod assumenda tempore cupiditate rerum
molestias cumque esse beatae debitis nisi facere placeat, asperiores ab
facilis atque nihil dignissimos veniam a!
<ThemeToggle client:only="preact" />
</Fragment>
</Layout>
8 changes: 5 additions & 3 deletions src/styles/utilities.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ body,
--color-text: 33 33 33;
}

:root[class~='dark'] {
--color-primary: 51 51 51;
--color-text: 241 234 229;
@media (prefers-color-scheme: dark) {
:root {
--color-primary: 33 33 33;
--color-text: 241 234 229;
}
}

h1,
Expand Down

0 comments on commit 756c1fb

Please sign in to comment.