2023-11-13 19:38:09 -05:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
import { useEffect, useState } from "react";
|
2023-10-25 12:56:51 -04:00
|
|
|
import { HiOutlineUserGroup } from "react-icons/hi2";
|
2023-10-29 13:27:16 -04:00
|
|
|
import AvatarStack from "@/components/ProfileContainers/AvatarStack";
|
2023-11-13 19:38:09 -05:00
|
|
|
import useEvents from "@/lib/hooks/useEvents";
|
|
|
|
import { NDKKind } from "@nostr-dev-kit/ndk";
|
|
|
|
import { getTagValues, getTagAllValues } from "@/lib/nostr/utils";
|
|
|
|
import { removeDuplicates } from "@/lib/utils";
|
2023-10-25 12:56:51 -04:00
|
|
|
type AttendeesContainerProps = {
|
|
|
|
attendees: string[];
|
2023-11-13 19:38:09 -05:00
|
|
|
eventReference: string;
|
2023-10-25 12:56:51 -04:00
|
|
|
};
|
|
|
|
export default function AttendeesContainer({
|
2023-11-13 19:38:09 -05:00
|
|
|
attendees: _attendees,
|
|
|
|
eventReference,
|
2023-10-25 12:56:51 -04:00
|
|
|
}: AttendeesContainerProps) {
|
2023-11-13 19:38:09 -05:00
|
|
|
const [attendees, setAttendees] = useState(_attendees);
|
|
|
|
const { events } = useEvents({
|
|
|
|
filter: {
|
|
|
|
kinds: [31925 as NDKKind],
|
|
|
|
["#a"]: [eventReference],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const users = events
|
|
|
|
.filter((e) => getTagAllValues("l", e.tags).includes("accepted"))
|
|
|
|
.map((e) => e.pubkey);
|
|
|
|
|
|
|
|
setAttendees(removeDuplicates([..._attendees, ...users]));
|
|
|
|
}, [events]);
|
2023-10-25 12:56:51 -04:00
|
|
|
return (
|
|
|
|
<div className="overflow-hidden rounded-[1rem] border bg-muted p-[0.5rem]">
|
|
|
|
<div className="flex items-center gap-x-3 px-2 pb-2">
|
|
|
|
<HiOutlineUserGroup className="h-5 w-5" />
|
|
|
|
<h3 className="text-lg font-semibold">Attendees</h3>
|
|
|
|
</div>
|
2023-10-29 13:27:16 -04:00
|
|
|
<AvatarStack pubkeys={attendees} />
|
2023-10-25 12:56:51 -04:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|