108 lines
3.0 KiB
TypeScript
Raw Normal View History

2023-10-23 21:30:31 -04:00
"use client";
2023-11-01 12:10:52 -04:00
import { useEffect } from "react";
2023-10-23 21:30:31 -04:00
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,
2023-10-25 12:56:51 -04:00
getTagsAllValues,
2023-10-24 15:31:06 -04:00
getTagsValues,
} from "@/lib/nostr/utils";
2023-10-25 12:56:51 -04:00
2023-10-23 21:30:31 -04:00
import Header from "./_components/Header";
2023-10-25 12:56:51 -04:00
import HostsContainer from "./_components/HostsContainer";
import LocationContainer from "./_components/LocationContainer";
import AnnouncementsContainer from "./_components/AnnouncementsContainer";
2023-10-25 15:15:56 -04:00
import DiscussionContainer from "./_components/DiscussionContainer";
2023-10-25 12:56:51 -04:00
import AttendeesContainer from "./_components/AttendeesContainer";
2023-11-01 12:10:52 -04:00
import { add, get } from "@/lib/server-actions/events/cache";
import { BANNER } from "@/constants";
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];
2023-11-01 12:10:52 -04:00
useEffect(() => {
if (event) {
const { tags, content } = event;
const name = getTagValues("name", tags) ?? "Untitled";
const image =
getTagValues("image", tags) ??
getTagValues("picture", tags) ??
getTagValues("banner", tags) ??
BANNER;
add({
identifier: naddr,
name: name,
description: content,
image: image,
});
}
}, [event]);
2023-10-23 21:30:31 -04:00
if (!event) {
return (
<div className="center pt-20 text-primary">
<Spinner />
</div>
);
}
2023-10-25 12:56:51 -04:00
const { tags } = event;
const eventReference = event.encode();
2023-10-25 15:15:56 -04:00
2023-10-25 12:56:51 -04:00
const location = getTagAllValues("location", tags)[0]
? getTagAllValues("location", tags)
: getTagAllValues("address", tags);
const geohash = getTagValues("g", tags);
const hosts = getTagsAllValues("p", tags)
.filter(([pubkey, relay, role]) => role === "host")
.map(([pubkey]) => pubkey)
.filter(Boolean);
const attendees = getTagsAllValues("p", tags)
.map(([pubkey]) => pubkey)
.filter(Boolean);
2023-10-23 21:30:31 -04:00
return (
2023-10-25 12:56:51 -04:00
<div className="relative mx-auto max-w-5xl space-y-4 p-2 @container sm:p-4">
2023-10-23 21:30:31 -04:00
<Header event={event} />
2023-10-25 12:56:51 -04:00
<div className="flex flex-col gap-4 @2xl:flex-row-reverse">
<div className="flex min-w-[250px] flex-1 flex-col gap-4">
2023-10-24 15:59:32 -04:00
{!!location && !!geohash && (
2023-10-25 12:56:51 -04:00
<LocationContainer
2023-10-24 15:31:06 -04:00
address={location[0] as string}
2023-10-25 12:56:51 -04:00
geohash={geohash}
2023-10-24 15:31:06 -04:00
/>
)}
2023-10-25 12:56:51 -04:00
<HostsContainer hosts={hosts} />
<AttendeesContainer attendees={attendees} />
</div>
2023-10-25 15:15:56 -04:00
<div className="max-w-2xl grow space-y-4">
<AnnouncementsContainer
eventReference={eventReference}
hosts={hosts}
/>
<DiscussionContainer eventReference={eventReference} />
2023-10-23 21:30:31 -04:00
</div>
</div>
</div>
);
}