2023-10-16 10:59:28 -04:00
|
|
|
"use client";
|
2023-10-14 12:09:44 -04:00
|
|
|
import {
|
|
|
|
Section,
|
|
|
|
SectionHeader,
|
|
|
|
SectionTitle,
|
|
|
|
SectionContent,
|
|
|
|
} from "@/containers/PageSection";
|
|
|
|
import LiveBadge from "@/components/Badges/LiveBadge";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
import { RiArrowRightLine } from "react-icons/ri";
|
2023-10-16 10:59:28 -04:00
|
|
|
import VideoCard, { VideoCardLoading } from "@/components/VideoCard";
|
2023-10-14 12:09:44 -04:00
|
|
|
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
|
2023-10-16 10:59:28 -04:00
|
|
|
import Link from "next/link";
|
|
|
|
import useEvents from "@/lib/hooks/useEvents";
|
|
|
|
import { Event } from "nostr-tools";
|
|
|
|
import KindLoading from "@/components/KindCard/loading";
|
|
|
|
import { nip19 } from "nostr-tools";
|
|
|
|
import { getTagValues, getTagsValues } from "@/lib/nostr/utils";
|
|
|
|
import { NOTABLE_ACCOUNTS } from "@/constants";
|
2023-10-16 13:01:46 -04:00
|
|
|
import { type NDKKind } from "@nostr-dev-kit/ndk";
|
2023-10-16 10:59:28 -04:00
|
|
|
import { uniqBy } from "ramda";
|
|
|
|
|
2023-10-14 12:09:44 -04:00
|
|
|
export default function LiveStreamingSection() {
|
2023-10-16 10:59:28 -04:00
|
|
|
const { events } = useEvents({
|
|
|
|
filter: {
|
|
|
|
kinds: [30311 as NDKKind],
|
|
|
|
limit: 5,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-10-16 11:23:37 -04:00
|
|
|
const processedEvents = uniqBy(
|
|
|
|
(e) => getTagValues("title", e.tags),
|
|
|
|
events,
|
|
|
|
).sort((a, b) => {
|
|
|
|
const aParticipants =
|
|
|
|
getTagValues("total_participants", a.tags) ??
|
|
|
|
getTagValues("current_participants", a.tags);
|
|
|
|
const bParticipants =
|
|
|
|
getTagValues("total_participants", b.tags) ??
|
|
|
|
getTagValues("current_participants", b.tags);
|
|
|
|
if (aParticipants && bParticipants) {
|
|
|
|
if (parseInt(aParticipants) < parseInt(bParticipants)) {
|
|
|
|
return 1;
|
|
|
|
} else return -1;
|
|
|
|
}
|
|
|
|
if (bParticipants) return 1;
|
|
|
|
return -1;
|
|
|
|
});
|
2023-10-14 12:09:44 -04:00
|
|
|
return (
|
2023-10-14 22:51:37 -04:00
|
|
|
<Section className="max-sm:-mx-5">
|
2023-10-14 12:09:44 -04:00
|
|
|
<SectionHeader>
|
2023-10-14 22:51:37 -04:00
|
|
|
<div className="center gap-x-2 max-sm:px-5">
|
2023-10-14 12:09:44 -04:00
|
|
|
<SectionTitle>Streaming Now</SectionTitle>
|
|
|
|
<LiveBadge text={"LIVE"} />
|
|
|
|
</div>
|
|
|
|
<Button variant={"ghost"}>
|
|
|
|
View all <RiArrowRightLine className="ml-1 h-4 w-4" />
|
|
|
|
</Button>
|
|
|
|
</SectionHeader>
|
|
|
|
<SectionContent className="relative">
|
|
|
|
<ScrollArea>
|
2023-10-14 22:51:37 -04:00
|
|
|
<div className="flex space-x-2 pb-4 max-sm:px-5">
|
2023-10-16 10:59:28 -04:00
|
|
|
{processedEvents?.length > 3 ? (
|
|
|
|
processedEvents
|
|
|
|
.filter((e) => !!getTagValues("summary", e.tags))
|
|
|
|
.slice(0, 6)
|
|
|
|
.map((e, idx) => {
|
|
|
|
const event = e.rawEvent() as Event;
|
|
|
|
const image = getTagValues("image", event.tags) as string;
|
|
|
|
const title = getTagValues("title", event.tags) as string;
|
|
|
|
const starts = getTagValues("starts", event.tags) as string;
|
2023-10-16 11:23:37 -04:00
|
|
|
const ends = getTagValues("ends", event.tags) as string;
|
2023-10-16 10:59:28 -04:00
|
|
|
const tags = getTagsValues("t", event.tags) as string[];
|
2023-10-16 11:08:11 -04:00
|
|
|
const total_participants =
|
|
|
|
getTagValues("total_participants", event.tags) ??
|
|
|
|
(getTagValues(
|
|
|
|
"current_participants",
|
|
|
|
event.tags,
|
|
|
|
) as string);
|
2023-10-16 10:59:28 -04:00
|
|
|
const status = getTagValues("status", event.tags) as
|
|
|
|
| "live"
|
|
|
|
| "planned"
|
|
|
|
| "ended";
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Link key={e.id} href={`/article/${e.encode()}`}>
|
|
|
|
<VideoCard
|
|
|
|
card={{
|
|
|
|
image,
|
|
|
|
tags,
|
|
|
|
title,
|
|
|
|
starts: parseInt(starts),
|
2023-10-16 11:23:37 -04:00
|
|
|
ends: parseInt(ends),
|
2023-10-16 10:59:28 -04:00
|
|
|
total_participants: total_participants
|
|
|
|
? parseInt(total_participants)
|
|
|
|
: undefined,
|
|
|
|
status,
|
|
|
|
}}
|
|
|
|
className="min-w-[250px] max-w-[350px]"
|
|
|
|
/>
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
})
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<VideoCardLoading className="min-w-[250px] max-w-[350px]" />
|
|
|
|
<VideoCardLoading className="min-w-[250px] max-w-[350px]" />
|
|
|
|
<VideoCardLoading className="min-w-[250px] max-w-[350px]" />
|
|
|
|
<VideoCardLoading className="min-w-[250px] max-w-[350px]" />
|
|
|
|
</>
|
|
|
|
)}
|
2023-10-14 12:09:44 -04:00
|
|
|
</div>
|
|
|
|
<ScrollBar orientation="horizontal" />
|
|
|
|
</ScrollArea>
|
|
|
|
</SectionContent>
|
|
|
|
</Section>
|
|
|
|
);
|
|
|
|
}
|