diff --git a/src/components/scroll/bottom-to-top.tsx b/src/components/scroll/bottom-to-top.tsx index 3b11d860..1c77295e 100644 --- a/src/components/scroll/bottom-to-top.tsx +++ b/src/components/scroll/bottom-to-top.tsx @@ -1,8 +1,16 @@ -import React, { useEffect, useState } from "react"; +import React, { useState, useEffect } from "react"; import { FaArrowUp } from "react-icons/fa"; export default function ScrollBottomToTop() { - const [showButton, setShowButton] = useState(false); + const [isVisible, setIsVisible] = useState(false); + + const toggleVisibility = () => { + if (window.pageYOffset > 300) { + setIsVisible(true); + } else { + setIsVisible(false); + } + }; const scrollToTop = () => { window.scrollTo({ @@ -11,29 +19,25 @@ export default function ScrollBottomToTop() { }); }; - const handleScroll = () => { - if (window.scrollY > 300) { - setShowButton(true); - } else { - setShowButton(false); - } - }; - useEffect(() => { - window.addEventListener("scroll", handleScroll); + window.addEventListener("scroll", toggleVisibility); + return () => { - window.removeEventListener("scroll", handleScroll); + window.removeEventListener("scroll", toggleVisibility); }; }, []); return ( - showButton && ( - - ) +
+ {isVisible && ( + + )} +
); } diff --git a/src/components/scroll/top-to-bottom.tsx b/src/components/scroll/top-to-bottom.tsx deleted file mode 100644 index 98b2bbdf..00000000 --- a/src/components/scroll/top-to-bottom.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import React, { useEffect, useState } from "react"; -import { FaArrowDown } from "react-icons/fa"; - -export default function ScrollTopToBottom() { - const [showButton, setShowButton] = useState(false); - - const scrollToBottom = () => { - window.scrollTo({ - top: document.documentElement.scrollHeight, - behavior: "smooth", - }); - }; - - const handleScroll = () => { - const bottomThreshold = - document.documentElement.scrollHeight - window.innerHeight - 100; - if (window.scrollY < bottomThreshold) { - setShowButton(true); - } else { - setShowButton(false); - } - }; - - useEffect(() => { - window.addEventListener("scroll", handleScroll); - return () => { - window.removeEventListener("scroll", handleScroll); - }; - }, []); - - return ( - showButton && ( - - ) - ); -} diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 02895a95..292442b9 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -6,7 +6,7 @@ import type { ReactNode } from "react"; import Head from "@docusaurus/Head"; import Header from "../components/header/header"; import ScrollBottomToTop from "../components/scroll/bottom-to-top"; -import ScrollTopToBottom from "../components/scroll/top-to-bottom"; + import { BlogCarousel } from "../components/blogCarousel/blogCarousel"; import OurProjects from "../components/ourProjects"; import TopMateSection from "../components/topmate/TopMateSection"; @@ -107,11 +107,9 @@ export default function Home(): ReactNode {
- - - + ); }