1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2025-01-09 17:37:40 +01:00
smov/src/pages/parts/home/HeroPart.tsx

64 lines
1.9 KiB
TypeScript
Raw Normal View History

2023-08-20 18:45:07 +02:00
import { useCallback, useState } from "react";
import Sticky from "react-sticky-el";
2023-08-20 18:45:07 +02:00
import { SearchBarInput } from "@/components/form/SearchBar";
2023-08-20 18:45:07 +02:00
import { ThinContainer } from "@/components/layout/ThinContainer";
import { HeroTitle } from "@/components/text/HeroTitle";
2023-10-25 16:58:38 +02:00
import { useRandomTranslation } from "@/hooks/useRandomTranslation";
2023-08-20 18:45:07 +02:00
import { useSearchQuery } from "@/hooks/useSearchQuery";
2023-10-21 21:44:08 +02:00
import { useBannerSize } from "@/stores/banner";
2023-08-20 18:45:07 +02:00
export interface HeroPartProps {
setIsSticky: (val: boolean) => void;
searchParams: ReturnType<typeof useSearchQuery>;
}
export function HeroPart({ setIsSticky, searchParams }: HeroPartProps) {
2023-10-25 16:58:38 +02:00
const { t } = useRandomTranslation();
2023-08-20 18:45:07 +02:00
const [search, setSearch, setSearchUnFocus] = searchParams;
const [, setShowBg] = useState(false);
const bannerSize = useBannerSize();
const stickStateChanged = useCallback(
(isFixed) => {
setShowBg(isFixed);
setIsSticky(isFixed);
2023-08-20 18:45:07 +02:00
},
[setShowBg, setIsSticky]
);
2023-10-25 16:58:38 +02:00
let time = "night";
const hour = new Date().getHours();
if (hour < 12) time = "morning";
2023-10-25 18:16:25 +02:00
else if (hour < 19) time = "day";
2023-10-25 16:58:38 +02:00
const title = t(`search.title.${time}`);
2023-08-20 18:45:07 +02:00
return (
<ThinContainer>
<div className="mt-44 space-y-16 text-center">
<div className="relative z-10 mb-16">
2023-10-25 16:58:38 +02:00
<HeroTitle className="mx-auto max-w-xs">{title}</HeroTitle>
2023-08-20 18:45:07 +02:00
</div>
<div className="relative h-20 z-30">
2023-08-20 18:45:07 +02:00
<Sticky
topOffset={-16 + bannerSize}
stickyStyle={{
paddingTop: `${16 + bannerSize}px`,
}}
onFixedToggle={stickStateChanged}
2023-08-20 18:45:07 +02:00
>
<SearchBarInput
onChange={setSearch}
value={search}
onUnFocus={setSearchUnFocus}
placeholder={
t("search.placeholder") || "What do you want to watch?"
}
/>
</Sticky>
</div>
</div>
</ThinContainer>
);
}