79 lines
2.1 KiB
TypeScript
Raw Normal View History

2023-10-23 21:30:31 -04:00
"use client";
import { useState } from "react";
import Image from "next/image";
import { nip19 } from "nostr-tools";
import useEvents from "@/lib/hooks/useEvents";
import Spinner from "@/components/spinner";
2023-10-24 15:31:06 -04:00
import {
getTagAllValues,
getTagValues,
getTagsValues,
} from "@/lib/nostr/utils";
2023-10-23 21:30:31 -04:00
import Feed from "@/containers/Feed";
import Header from "./_components/Header";
2023-10-24 15:31:06 -04:00
import LocationPreview from "@/components/LocationPreview";
2023-10-23 21:30:31 -04:00
export default function EventPage({
params: { naddr },
}: {
params: {
naddr: string;
};
}) {
const { type, data } = nip19.decode(naddr);
if (type !== "naddr") {
throw new Error("Invalid list");
}
const { identifier, kind, pubkey } = data;
const { events } = useEvents({
filter: {
authors: [pubkey],
kinds: [kind],
["#d"]: [identifier],
limit: 1,
},
});
const event = events[0];
if (!event) {
return (
<div className="center pt-20 text-primary">
<Spinner />
</div>
);
}
const noteIds = getTagsValues("e", event.tags).filter(Boolean);
2023-10-24 15:31:06 -04:00
const location = getTagAllValues("location", event.tags)[0]
? getTagAllValues("location", event.tags)
: getTagAllValues("address", event.tags);
2023-10-24 15:59:32 -04:00
const geohash = getTagValues("g", event.tags);
2023-10-23 21:30:31 -04:00
return (
<div className="relative mx-auto max-w-5xl space-y-4 p-2 sm:p-4">
<Header event={event} />
<div className="relative overflow-hidden rounded-[1rem] border bg-muted p-[0.5rem] @container">
2023-10-24 15:59:32 -04:00
<div className="flex flex-col gap-3 @xl:flex-row-reverse">
{!!location && !!geohash && (
2023-10-24 15:31:06 -04:00
<LocationPreview
2023-10-24 15:59:32 -04:00
geohash={geohash}
2023-10-24 15:31:06 -04:00
address={location[0] as string}
/>
)}
2023-10-24 15:59:32 -04:00
<div className="flex-1 space-y-3 overflow-hidden rounded-[0.5rem] p-0">
<Feed
filter={{
ids: noteIds,
}}
empty={() => (
2023-10-24 18:06:23 -04:00
<div className="py-5 text-center text-muted-foreground">
2023-10-24 15:59:32 -04:00
<p>No Announcements yet</p>
</div>
)}
/>
</div>
2023-10-23 21:30:31 -04:00
</div>
</div>
</div>
);
}