"use client"; import { useState, useEffect } from "react"; import Link from "next/link"; import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar"; import { nip19 } from "nostr-tools"; import { getLettersPlain } from "@/lib/utils"; import { Skeleton } from "@/components/ui/skeleton"; import { HiMiniChevronRight, HiCalendarDays } from "react-icons/hi2"; import useEvents from "@/lib/hooks/useEvents"; import { getTagValues } from "@/lib/nostr/utils"; import ProfileInfo from "./ProfileInfo"; import { type NDKKind, type NDKEvent } from "@nostr-dev-kit/ndk"; import { useNDK } from "@/app/_providers/ndk"; type CalendarInfoProps = { eventReference: string; }; export default function CalendarInfo({ eventReference }: CalendarInfoProps) { console.log("eventReference", eventReference); const [kind, pubkey, identifier] = eventReference.split(":") as [ string, string, string, ]; const { ndk } = useNDK(); const [event, setEvent] = useState(); const [isFetching, setIsFetching] = useState(false); useEffect(() => { if (!ndk || isFetching || event) return; handleFetchEvent(); }, [ndk, eventReference]); async function handleFetchEvent() { if (!ndk) return; setIsFetching(true); const calendarEvent = await ndk .fetchEvent({ authors: [pubkey], ["#a"]: [eventReference], kinds: [31924 as NDKKind], }) .catch((err) => console.log("err")); if (calendarEvent) { console.log("Found calendar", calendarEvent); setEvent(calendarEvent); } setIsFetching(false); } if (!event) { return ; } const image = getTagValues("image", event.tags); const name = getTagValues("name", event.tags); return ( {getLettersPlain(name)}
{name ?? "Calendar"}
); } export function LoadingCalendarInfo() { return (
); }