import { useCallback, useEffect, useRef, useState } from "react"; import Sticky from "react-sticky-el"; import { useWindowSize } from "react-use"; import { SearchBarInput } from "@/components/form/SearchBar"; import { ThinContainer } from "@/components/layout/ThinContainer"; import { useSlashFocus } from "@/components/player/hooks/useSlashFocus"; import { HeroTitle } from "@/components/text/HeroTitle"; import { useRandomTranslation } from "@/hooks/useRandomTranslation"; import { useSearchQuery } from "@/hooks/useSearchQuery"; import { useBannerSize } from "@/stores/banner"; export interface HeroPartProps { setIsSticky: (val: boolean) => void; searchParams: ReturnType; } function getTimeOfDay(date: Date): "night" | "morning" | "day" { const hour = date.getHours(); if (hour < 5) return "night"; if (hour < 12) return "morning"; if (hour < 19) return "day"; return "night"; } export function HeroPart({ setIsSticky, searchParams }: HeroPartProps) { const { t: randomT } = useRandomTranslation(); const [search, setSearch, setSearchUnFocus] = searchParams; const [, setShowBg] = useState(false); const bannerSize = useBannerSize(); const stickStateChanged = useCallback( (isFixed: boolean) => { setShowBg(isFixed); setIsSticky(isFixed); }, [setShowBg, setIsSticky], ); const { width: windowWidth } = useWindowSize(); const topSpacing = 16; const [stickyOffset, setStickyOffset] = useState(topSpacing); useEffect(() => { if (windowWidth > 1200) { // On large screens the bar goes inline with the nav elements setStickyOffset(topSpacing); } else { // On smaller screens the bar goes below the nav elements setStickyOffset(topSpacing + 60); } }, [windowWidth]); const time = getTimeOfDay(new Date()); const title = randomT(`home.titles.${time}`); const placeholder = randomT(`home.search.placeholder`); const inputRef = useRef(null); useSlashFocus(inputRef); return (
{title}
); }