From 57ad6b5fa747c534e4a58aac9395de14f5379bb1 Mon Sep 17 00:00:00 2001 From: soyoka <55011525+soy0ka@users.noreply.github.com> Date: Sat, 19 Apr 2025 01:37:04 +0900 Subject: [PATCH] feat: show search bar when scrolled --- components/Navbar.tsx | 25 +++++++++++++++++++++---- components/Search.tsx | 38 ++++++++++++++++++++++---------------- 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/components/Navbar.tsx b/components/Navbar.tsx index c86d80d..d0d5080 100644 --- a/components/Navbar.tsx +++ b/components/Navbar.tsx @@ -11,6 +11,7 @@ import { useEffect, useState } from 'react' import { Nullable, User, UserCache } from '@types' import Fetch from '@utils/Fetch' import { redirectTo } from '@utils/Tools' +import Search from './Search' const DiscordAvatar = dynamic(() => import('@components/DiscordAvatar')) @@ -51,9 +52,20 @@ const Navbar: React.FC = ({ token }) => { setUserCache(null) } }, [token]) + const [scrolled, setScrolled] = useState(false) + + useEffect(() => { + const handleScroll = () => setScrolled(window.scrollY > 80) + window.addEventListener('scroll', handleScroll) + return () => window.removeEventListener('scroll', handleScroll) + }, []) + return ( - <> -