2023-10-28 11:07:50 -04:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
import { cn } from "@/lib/utils";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
import { RiArrowRightLine } from "react-icons/ri";
|
|
|
|
import useEvents from "@/lib/hooks/useEvents";
|
|
|
|
import { nip19 } from "nostr-tools";
|
2023-11-02 09:14:30 -04:00
|
|
|
import { NDKEvent, type NDKKind } from "@nostr-dev-kit/ndk";
|
2023-11-01 17:07:11 -04:00
|
|
|
import { uniqBy } from "ramda";
|
2023-10-28 11:07:50 -04:00
|
|
|
|
2023-10-30 09:55:09 -04:00
|
|
|
import CalendarCard, { LoadingCalendarCard } from "../_components/CalendarCard";
|
2023-11-01 17:07:11 -04:00
|
|
|
import { getTagValues } from "@/lib/nostr/utils";
|
2023-11-02 09:12:09 -04:00
|
|
|
|
2023-10-28 11:07:50 -04:00
|
|
|
export default function ExploreCalendars() {
|
|
|
|
return (
|
|
|
|
<section className="relative -mx-5 space-y-4 overflow-x-hidden sm:space-y-6">
|
|
|
|
<div className="flex items-center justify-between px-5 max-sm:pr-3">
|
|
|
|
<h2 className="font-condensed text-2xl font-bold sm:text-3xl">
|
|
|
|
Explore Calendars
|
|
|
|
</h2>
|
|
|
|
<Button variant={"ghost"}>
|
|
|
|
View all <RiArrowRightLine className="ml-1 h-4 w-4" />
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
<HorizontalCarousel />
|
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function HorizontalCarousel() {
|
|
|
|
const { events } = useEvents({
|
|
|
|
filter: {
|
|
|
|
kinds: [31924 as NDKKind],
|
|
|
|
limit: 5,
|
|
|
|
},
|
|
|
|
});
|
2023-11-02 09:12:09 -04:00
|
|
|
console.log("explore calendars", events);
|
2023-10-30 09:55:09 -04:00
|
|
|
|
|
|
|
if (events.length) {
|
|
|
|
return (
|
|
|
|
<div className="scrollbar-thumb-rounded-full mr-auto flex min-w-0 max-w-full snap-x snap-mandatory overflow-x-auto pl-5 pr-[50vw] scrollbar-thin sm:pr-[200px]">
|
2023-11-02 09:12:09 -04:00
|
|
|
{uniqBy((e) => getTagValues("d", e.tags), events).map(
|
2023-11-01 17:07:11 -04:00
|
|
|
(calendar, index) => (
|
|
|
|
<div
|
|
|
|
key={calendar.id}
|
|
|
|
className={cn("snap-start pl-2 sm:pl-5", index === 0 && "pl-5")}
|
|
|
|
>
|
2023-11-02 09:14:30 -04:00
|
|
|
<Calendar event={calendar} />
|
2023-11-01 17:07:11 -04:00
|
|
|
</div>
|
|
|
|
),
|
|
|
|
)}
|
2023-10-30 09:55:09 -04:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-10-28 11:07:50 -04:00
|
|
|
return (
|
|
|
|
<div className="scrollbar-thumb-rounded-full mr-auto flex min-w-0 max-w-full snap-x snap-mandatory overflow-x-auto pl-5 pr-[50vw] scrollbar-thin sm:pr-[200px]">
|
2023-10-30 09:55:09 -04:00
|
|
|
{Array.from(Array(5)).map((_, index) => (
|
2023-10-28 11:07:50 -04:00
|
|
|
<div
|
|
|
|
key={index}
|
|
|
|
className={cn("snap-start pl-2 sm:pl-5", index === 0 && "pl-5")}
|
|
|
|
>
|
2023-10-30 09:55:09 -04:00
|
|
|
<LoadingCalendarCard />
|
2023-10-28 11:07:50 -04:00
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-11-02 09:14:30 -04:00
|
|
|
function Calendar({ event }: { event: NDKEvent }) {
|
|
|
|
return <CalendarCard calendar={event} />;
|
2023-10-28 11:07:50 -04:00
|
|
|
}
|