From 75808307a44b21e6013cb4f6735ad32d80e0709e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Veikko=20Lintuj=C3=A4rvi?= Date: Thu, 7 May 2026 23:11:45 +0300 Subject: [PATCH] Some basic improvements --- src/App.jsx | 49 +++++++++++++++++-- src/App.module.scss | 32 ++++++++++++ src/components/About/About.jsx | 21 ++++---- src/components/About/About.module.scss | 2 +- src/components/Contact/Contact.jsx | 13 +++-- src/components/Contact/Contact.module.scss | 4 +- src/components/Footer/Footer.jsx | 4 +- src/components/Hero/Hero.jsx | 10 ++-- src/components/Hero/Hero.module.scss | 10 ++-- src/components/Navbar/Navbar.jsx | 34 ++++++++----- src/components/Navbar/Navbar.module.scss | 21 +++++++- src/components/Projects/Projects.jsx | 18 +++---- src/components/Projects/Projects.module.scss | 12 ++--- src/components/ThemeToggle/ThemeToggle.jsx | 42 ++++++++++++++++ .../ThemeToggle/ThemeToggle.module.scss | 19 +++++++ src/state/atoms.js | 2 + src/styles/_global.scss | 32 ++++++++++++ src/styles/_variables.scss | 24 ++++----- 18 files changed, 271 insertions(+), 78 deletions(-) create mode 100644 src/App.module.scss create mode 100644 src/components/ThemeToggle/ThemeToggle.jsx create mode 100644 src/components/ThemeToggle/ThemeToggle.module.scss diff --git a/src/App.jsx b/src/App.jsx index 86f7f4a..bc5d765 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,19 +1,58 @@ +import { useState, useEffect, useRef } from 'react'; +import { useAtomValue } from 'jotai'; +import { activeSectionState, themeState } from './state/atoms'; import Navbar from './components/Navbar/Navbar'; import Hero from './components/Hero/Hero'; import About from './components/About/About'; import Projects from './components/Projects/Projects'; import Contact from './components/Contact/Contact'; import Footer from './components/Footer/Footer'; +import styles from './App.module.scss'; + +const SECTIONS = { + home: Hero, + about: About, + projects: Projects, + contact: Contact, +}; + +const EXIT_DURATION = 200; export default function App() { + const activeSection = useAtomValue(activeSectionState); + const theme = useAtomValue(themeState); + const [displayedSection, setDisplayedSection] = useState(activeSection); + const [isExiting, setIsExiting] = useState(false); + const timerRef = useRef(null); + + useEffect(() => { + if (theme === 'light') { + document.documentElement.dataset.theme = 'light'; + } else { + delete document.documentElement.dataset.theme; + } + }, [theme]); + + useEffect(() => { + if (activeSection === displayedSection) return; + setIsExiting(true); + timerRef.current = setTimeout(() => { + setDisplayedSection(activeSection); + setIsExiting(false); + }, EXIT_DURATION); + return () => clearTimeout(timerRef.current); + }, [activeSection]); + + const Section = SECTIONS[displayedSection] ?? Hero; + return ( <> -
- - - - +
+