"use client"; import { useRef, useEffect, useState } from "react"; import { formatDate, fromUnix, relativeTime, addMinutesToDate, } from "@/lib/utils/dates"; import useCurrentUser from "@/lib/hooks/useCurrentUser"; import { NDKEvent } from "@nostr-dev-kit/ndk"; import { getTagValues } from "@/lib/nostr/utils"; import LargeFeedCard, { LoadingCard, } from "@/components/Cards/CalendarEvent/LargeFeedCard"; import { cn } from "@/lib/utils"; type CalendarSectionProps = { events: NDKEvent[]; }; export default function CalendarSection({ events }: CalendarSectionProps) { const { currentUser } = useCurrentUser(); const firstEvent = events.at(0); if (!firstEvent) return null; const startDateUnix = getTagValues("start", firstEvent?.tags); if (!startDateUnix) return null; const startDate = fromUnix(parseInt(startDateUnix)); return (
{/* Date Indicator */}
{/* Date Indicator Mobile */}
{/* Events */}
{events.map((e) => ( ))}
); } export function CalendarSectionLoading() { const startDate = addMinutesToDate(new Date(), 60); return (
{/* Date Indicator */}
{/* Date Indicator Mobile */}
{/* Events */}
); } function CalendarIcon({ date }: { date: Date }) { return (
{/* 24 */} {formatDate(date, "ddd")}
{formatDate(date, "MMMM Do")} {relativeTime(date)}
); } function CalendarIconOpacity({ date }: { date: Date }) { const ref = useRef(null); const [top, setTop] = useState(false); useEffect(() => { // Add a scroll event listener to the window const handleScroll = () => { if (ref.current) { // Get the position of the div relative to the viewport const divRect = ref.current.getBoundingClientRect(); // Change the opacity when the div reaches the top of the screen if (divRect.top <= 145) { setTop(true); } else { setTop(false); } } }; window.addEventListener("scroll", handleScroll); return () => { // Remove the scroll event listener when the component unmounts window.removeEventListener("scroll", handleScroll); }; }, []); return (
); }