import titleImg from "@/assets/images/title-img.svg"; import PageMetadata from "@/components/containers/PageMetadata"; import { cn } from "@/utility/utils"; import dayjs from "dayjs"; import { ComponentProps, useEffect, useMemo, useRef, useState } from "react"; import { Link } from "react-router-dom"; import { icons } from "./icons"; import { useQuery } from "react-query"; import pb from "@/utility/api"; const HomePage = () => { return (
); }; const BackgroundSlideshow = () => { const slideshowTimer = 10000; const { data: wallpapers } = useQuery({ queryKey: ["wallpapers"], queryFn: async () => { const items = await pb.collection("wallpapers").getFullList({ sort: "@random", expand: "artwork", }); return items.map((item) => { const artwork = item.expand?.artwork; const img = pb.files.getUrl(artwork, artwork?.image); return { ...artwork, src: img }; }); }, refetchOnWindowFocus: false, }); const [currentIdx, setCurrentIdx] = useState(0); const curArtwork = wallpapers?.[currentIdx]; useEffect(() => { if (!wallpapers) { return; } const intv = setInterval(() => { setCurrentIdx((cur) => (cur + 1) % wallpapers.length); }, slideshowTimer); return () => { clearInterval(intv); }; }, [wallpapers, slideshowTimer]); return ( <> title {curArtwork ? ( ) : null} ); }; type BackgroundImageProps = { src: string; artwork: any; }; const BackgroundImage = ({ src, artwork }: BackgroundImageProps) => { const lastChangeRef = useRef(null); const [isLoaded, setLoaded] = useState(false); const [imgSrc, setImgSrc] = useState(""); useEffect(() => { setLoaded(false); lastChangeRef.current = new Date(); }, [src]); const onLoaded = () => { setLoaded(true); setImgSrc(src); }; return ( <> img { let timer = lastChangeRef.current ? new Date().getMilliseconds() - lastChangeRef.current.getMilliseconds() : 100; timer = Math.max(500, Math.min(timer, 1000)); setTimeout(onLoaded, timer); }} />
{`Illustration by ${artwork.artistName}`}
); }; const DateTime = () => { const [time, setTime] = useState(new Date()); useEffect(() => { const intv = setInterval(() => { setTime(new Date()); }, 1000); return () => { clearInterval(intv); }; }, [setTime]); const message = useMemo(() => { const hours = time.getHours(); let msg = "Day"; if (hours >= 18 && hours <= 2) { msg = "Night"; } else if (hours > 2 && hours <= 9) { msg = "Morning"; } else if (hours > 9 && hours <= 15) { msg = "Day"; } else if (hours > 15 && hours < 18) { msg = "Evening"; } return `Good ${msg}~ 💧✨`; }, [time]); return (

{message}

{dayjs(time).format("HH:mm")}

{dayjs(time).format("dddd, DD MMM YYYY")}

); }; const AppNav = ({ className }: ComponentProps<"div">) => { return (
); }; type AppNavItemProps = { title: string; icon: string; path?: string; iconClassName?: string; }; const AppNavItem = ({ title, icon, path, iconClassName }: AppNavItemProps) => { return (
{title}

{title}

); }; export default HomePage;