From 6523f08b2b663c4e620312201385f417550e4117 Mon Sep 17 00:00:00 2001 From: wodeni Date: Wed, 3 Jan 2024 02:29:24 -0500 Subject: [PATCH] chore: show news feed history --- src/App.tsx | 67 ++++++++++++++++++++++++++++++++++++--------------- src/index.css | 11 +++++++++ 2 files changed, 59 insertions(+), 19 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index c8948d4..92aa572 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,7 +4,7 @@ import edgeworth from "./assets/edgeworth.svg"; import mathdiagrams from "./assets/mathdiagrams.webp"; import Balls from "./Balls"; import Papers, { Paper } from "./Papers"; -import { HTMLProps, ReactNode, useEffect, useState } from "react"; +import { HTMLProps, ReactNode, useEffect, useRef, useState } from "react"; import { HashLink } from "react-router-hash-link"; import news from "./News"; import A from "./A"; @@ -22,26 +22,55 @@ import theme from "./theme"; const NewsFeed = () => { const today = new Date(); + const [isScrolled, setIsScrolled] = useState(false); + const scrollableDivRef = useRef(null); + + useEffect(() => { + const handleScroll = () => { + if (scrollableDivRef.current !== null) { + const isAtTop = scrollableDivRef.current.scrollTop === 0; + setIsScrolled(!isAtTop); + } + }; + if (scrollableDivRef.current !== null) { + const div = scrollableDivRef.current; + div.addEventListener("scroll", handleScroll); + // Cleanup function + return () => { + div.removeEventListener("scroll", handleScroll); + }; + } + }, []); + return ( -
- {news - .filter( - ({ time }) => time.getUTCFullYear() >= today.getUTCFullYear() - 1 - ) - .map(({ time, msg }, i) => ( -
-
- {time.toLocaleString("default", { - month: "long", - year: "numeric", - })} +
+ {isScrolled && ( +
+ )} +
+ {news + // .filter( + // ({ time }) => time.getUTCFullYear() >= today.getUTCFullYear() - 1 + // ) + .map(({ time, msg }, i) => ( +
+
+ {time.toLocaleString("default", { + month: "long", + year: "numeric", + })} +
+ {msg}
- {msg} -
- ))} + ))} +
+
); }; diff --git a/src/index.css b/src/index.css index 14f3185..23e5042 100644 --- a/src/index.css +++ b/src/index.css @@ -2,3 +2,14 @@ @import "tailwindcss/components"; @import "tailwindcss/utilities"; @import url("https://fonts.googleapis.com/css2?family=Open+Sans"); + +/* For Webkit-based browsers (Chrome, Safari and Opera) */ +.scrollbar-hide::-webkit-scrollbar { + display: none; +} + +/* For IE, Edge and Firefox */ +.scrollbar-hide { + -ms-overflow-style: none; /* IE and Edge */ + scrollbar-width: none; /* Firefox */ +}