"use client"; import { useState, useEffect } from "react"; import { formatDate, fromUnix } from "@/lib/utils/dates"; import Link from "next/link"; import { cn } from "@/lib/utils"; import { Button } from "@/components/ui/button"; import Image from "next/image"; import { nip19 } from "nostr-tools"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import SmallProfileLine from "@/components/ProfileContainers/SmallProfileLine"; import AvatarStack from "@/components/ProfileContainers/AvatarStack"; import { type NDKEvent, type NDKKind } from "@nostr-dev-kit/ndk"; import { useNDK } from "@/app/_providers/ndk"; import { getTagValues, getTagAllValues, getTagsValues, } from "@/lib/nostr/utils"; import { HiOutlineMapPin, HiOutlineUserCircle } from "react-icons/hi2"; import { RxClock, RxCalendar } from "react-icons/rx"; import { Skeleton } from "@/components/ui/skeleton"; import { AspectRatio } from "@/components/ui/aspect-ratio"; import SmallLineInfo from "@/components/CalendarContainers/SmallLineInfo"; type LargeFeedCardProps = { event: NDKEvent; }; export default function LargeFeedCard({ event }: LargeFeedCardProps) { const { tags, pubkey, content } = event; const image = getTagValues("image", tags); const location = getTagValues("location", tags) ?? getTagValues("address", tags); const users = getTagsValues("p", tags).filter(Boolean); const startDate = getTagValues("start", tags) ? new Date(parseInt(getTagValues("start", tags) as string) * 1000) : null; const endDate = getTagValues("end", tags) ? new Date(parseInt(getTagValues("end", tags) as string) * 1000) : null; return ( {getTagValues("name", tags)} {content} {!!users.length && ( 2 ? users.length - 4 : 0} /> )} {!!startDate && ( {formatDate(startDate, "h:mm a")} {!!endDate && ( <> {" "} - {formatDate(endDate, "h:mm a")} > )} )} {!!location && ( {location} )} RSVP Details {image ? ( ) : ( )} ); } export function LoadingCard() { return ( ); } function CalendarLine({ eventReference }: { eventReference: string }) { const { type, data } = nip19.decode(eventReference); if (type !== "naddr") { throw new Error("Invalid list"); } const { pubkey } = data; 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 ; } return ; }
{formatDate(startDate, "h:mm a")} {!!endDate && ( <> {" "} - {formatDate(endDate, "h:mm a")} > )}
{location}