diff --git a/src/App.tsx b/src/App.tsx index 126fb46..983dfc3 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,4 @@ -import { useEffect, useRef } from "react"; +import { useEffect, useRef, useState } from "react"; import "@styles/App.scss"; import Header from "@components/Header"; import About from "@sections/About"; @@ -13,10 +13,31 @@ export default function App() { const skillsRef = useRef(null); const projectsRef = useRef(null); + const [isScrolling, setIsScrolling] = useState(false); + + useEffect(() => { + const handleScroll = () => { + setIsScrolling(true); + + setTimeout(() => { + setIsScrolling(false); + }, 100); + }; + + window.addEventListener("scroll", handleScroll); + + return () => { + window.removeEventListener("scroll", handleScroll); + }; + }, []); + useEffect(() => { const observer = new IntersectionObserver( (entries) => { entries.forEach((entry) => { + if (isScrolling) { + return; + } if (entry.isIntersecting) { window.location.hash = entry.target.id; entry.target.classList.add("active"); diff --git a/src/sections/Projects.tsx b/src/sections/Projects.tsx index 368bc5f..2cac469 100644 --- a/src/sections/Projects.tsx +++ b/src/sections/Projects.tsx @@ -1,6 +1,7 @@ import "@styles/Projects.scss"; import Badge from "@components/Badge"; import { BadgeType } from "@components/BadgeType"; +import { useState, useEffect } from "react"; function Project({ name, @@ -13,10 +14,16 @@ function Project({ image?: string; link: string; }) { - const imageUrl = - image || - "https://source.unsplash.com/random/500x400?javascript&sig=" + - Math.random() * 1000; + const [imageUrl, setImageUrl] = useState(image); + + useEffect(() => { + if (!image) { + setImageUrl( + "https://source.unsplash.com/random/500x400?javascript&sig=" + + Math.random() * 1000 + ); + } + }, [image]); return (