From 6215310fa14f51f05cff9aad8466a68325438cd3 Mon Sep 17 00:00:00 2001 From: ayan4m1 Date: Sat, 13 Jan 2024 05:25:27 -0500 Subject: [PATCH] add theme context for switching dark mode and remembering with localStorage --- src/components/header.js | 48 +++++++++------------------------ src/components/layout.js | 9 +++---- src/components/themeProvider.js | 43 +++++++++++++++++++++++++++++ src/hooks/useDarkMode.js | 24 ----------------- src/hooks/useMediaQuery.js | 11 +++++--- src/hooks/useThemeContext.js | 7 +++++ 6 files changed, 73 insertions(+), 69 deletions(-) create mode 100644 src/components/themeProvider.js delete mode 100644 src/hooks/useDarkMode.js create mode 100644 src/hooks/useThemeContext.js diff --git a/src/components/header.js b/src/components/header.js index 05007ff..14b48c6 100644 --- a/src/components/header.js +++ b/src/components/header.js @@ -1,34 +1,22 @@ -import { useSpring, animated } from '@react-spring/web'; -import { Link, useStaticQuery, graphql } from 'gatsby'; -import { Container, Navbar, Nav, NavDropdown } from 'react-bootstrap'; - -import usePrefersReducedMotion from 'hooks/usePrefersReducedMotion'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faFileArchive, faGamepad, faHeart, + faMoon, faNewspaper, faRectangleList, + faSun, faTable } from '@fortawesome/free-solid-svg-icons'; import { Fragment } from 'react'; +import { Link, useStaticQuery, graphql } from 'gatsby'; +import { Container, Navbar, Nav, NavDropdown, Button } from 'react-bootstrap'; -const bobbleSpring = { - from: { y: 4 }, - to: [{ y: -4 }, { y: 4 }], - config: { - mass: 0.1, - tension: 20, - friction: 0.1 - }, - loop: true, - reset: false -}; +import { useThemeContext } from 'hooks/useThemeContext'; export default function Header() { - const [springs] = useSpring(() => bobbleSpring); - const disableMotion = usePrefersReducedMotion(); + const { darkMode, toggleDarkMode } = useThemeContext(); const data = useStaticQuery(graphql` query { site { @@ -97,23 +85,13 @@ export default function Header() { -