From 309a25c2dcf8825fd1c4803db2875b36a383988d Mon Sep 17 00:00:00 2001 From: zmeyer44 Date: Wed, 1 Nov 2023 17:04:49 -0400 Subject: [PATCH] improving cards --- .../CalendarContainers/SmallLineInfo.tsx | 46 +++++++++++++++++++ .../Cards/CalendarEvent/LargeFeedCard.tsx | 45 +++++++++++++++++- components/Cards/CalendarEvent/index.tsx | 2 +- 3 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 components/CalendarContainers/SmallLineInfo.tsx diff --git a/components/CalendarContainers/SmallLineInfo.tsx b/components/CalendarContainers/SmallLineInfo.tsx new file mode 100644 index 0000000..5069042 --- /dev/null +++ b/components/CalendarContainers/SmallLineInfo.tsx @@ -0,0 +1,46 @@ +import Link from "next/link"; +import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar"; +import useProfile from "@/lib/hooks/useProfile"; +import { nip19 } from "nostr-tools"; +import { getLettersPlain } from "@/lib/utils"; +import { Skeleton } from "@/components/ui/skeleton"; +import { HiCalendarDays } from "react-icons/hi2"; +import { NDKEvent } from "@nostr-dev-kit/ndk"; +import { getTagValues } from "@/lib/nostr/utils"; + +type SmallLineInfoProps = { + event: NDKEvent; +}; +export default function SmallLineInfo({ event }: SmallLineInfoProps) { + const image = getTagValues("image", event.tags); + const name = getTagValues("name", event.tags); + return ( + + + + + {getLettersPlain(name)} + + + +
+ {name ?? "Calendar"} + +
+ + ); +} + +export function LoadingProfileInfo() { + return ( +
+ +
+ +
+
+ ); +} diff --git a/components/Cards/CalendarEvent/LargeFeedCard.tsx b/components/Cards/CalendarEvent/LargeFeedCard.tsx index c054ad6..025f6c7 100644 --- a/components/Cards/CalendarEvent/LargeFeedCard.tsx +++ b/components/Cards/CalendarEvent/LargeFeedCard.tsx @@ -1,8 +1,11 @@ +"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, @@ -12,7 +15,8 @@ import { } from "@/components/ui/card"; import SmallProfileLine from "@/components/ProfileContainers/SmallProfileLine"; import AvatarStack from "@/components/ProfileContainers/AvatarStack"; -import { NDKEvent } from "@nostr-dev-kit/ndk"; +import { type NDKEvent, type NDKKind } from "@nostr-dev-kit/ndk"; +import { useNDK } from "@/app/_providers/ndk"; import { getTagValues, getTagAllValues, @@ -22,6 +26,7 @@ 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; @@ -33,7 +38,6 @@ export default function LargeFeedCard({ event }: LargeFeedCardProps) { const location = getTagValues("location", tags) ?? getTagValues("address", tags); const users = getTagsValues("p", tags).filter(Boolean); - console.log("Users", users); const startDate = getTagValues("start", tags) ? new Date(parseInt(getTagValues("start", tags) as string) * 1000) : null; @@ -161,3 +165,40 @@ export function LoadingCard() { ); } + +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 ; +} diff --git a/components/Cards/CalendarEvent/index.tsx b/components/Cards/CalendarEvent/index.tsx index 0515406..2746843 100644 --- a/components/Cards/CalendarEvent/index.tsx +++ b/components/Cards/CalendarEvent/index.tsx @@ -70,7 +70,7 @@ export default function CalendarEventCard({ height={150} unoptimized className={cn( - "h-auto w-auto object-cover transition-all group-hover:scale-105", + "h-auto w-auto min-w-full object-cover transition-all group-hover:scale-105", "aspect-video", )} />