"use client";
import { useRef, useEffect, useState } from "react";
import { CardLoading } from "@/components/Cards/CalendarEvent";
import { formatDate, fromUnix, relativeTime } from "@/lib/utils/dates";
import useCurrentUser from "@/lib/hooks/useCurrentUser";
import { DUMMY_1 } from "@/constants";
import { NDKEvent } from "@nostr-dev-kit/ndk";
import { getTagValues } from "@/lib/nostr/utils";
import LargeFeedCard 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) => (
))}
);
}
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 <= 110) {
setTop(true);
} else {
setTop(false);
}
}
};
window.addEventListener("scroll", handleScroll);
return () => {
// Remove the scroll event listener when the component unmounts
window.removeEventListener("scroll", handleScroll);
};
}, []);
return (
);
}