111 lines
3.4 KiB
TypeScript
Raw Normal View History

2023-10-14 18:57:37 -04:00
"use client";
import Image from "next/image";
import Link from "next/link";
import { RiMoreFill } from "react-icons/ri";
import { Card, CardContent, CardHeader } from "@/components/ui/card";
import { formatDate } from "@/lib/utils/dates";
import { Button } from "@/components/ui/button";
import { ReactNode } from "react";
2023-10-16 00:57:59 -04:00
import ProfileHeader, { LoadingProfileHeader } from "./ProfileHeader";
import { getTagValues, getTagsValues } from "@/lib/nostr/utils";
2023-10-14 18:57:37 -04:00
import Actions from "./Actions";
import Tags from "./Tags";
2023-10-15 11:44:15 -04:00
import DropDownMenu from "@/components/DropDownMenu";
import { removeDuplicates } from "@/lib/utils";
2023-10-20 15:26:55 -04:00
import { type KindCardProps } from "..";
2023-10-15 11:44:15 -04:00
type OptionLink = {
href: string;
type: "link";
};
type OptionButton = {
onClick: () => void;
type: "button";
};
type Option = {
label: string;
} & (OptionLink | OptionButton);
2023-10-14 18:57:37 -04:00
type CreatorCardProps = {
children: ReactNode;
2023-10-15 11:44:15 -04:00
actionOptions?: Option[];
2023-10-20 15:26:55 -04:00
event?: KindCardProps;
2023-10-14 18:57:37 -04:00
};
2023-10-15 11:44:15 -04:00
export default function Container({
children,
actionOptions = [],
event,
2023-10-15 11:44:15 -04:00
}: CreatorCardProps) {
if (!event) {
return (
<Card className="relative flex h-full w-full flex-col overflow-hidden @container">
<CardHeader className="flex flex-row items-center justify-between space-y-0 p-4 pb-4">
<LoadingProfileHeader />
<div className="-mr-1 flex items-center gap-x-1.5 text-xs text-muted-foreground">
<DropDownMenu options={[]}>
<Button
size={"sm"}
variant={"ghost"}
className="center h-6 w-6 p-0"
>
<RiMoreFill className="h-4 w-4" />
</Button>
</DropDownMenu>
</div>
</CardHeader>
<CardContent className="flex grow flex-col px-4 pb-3">
{children}
<div className="mt-auto"></div>
</CardContent>
</Card>
);
}
2023-10-20 15:26:55 -04:00
const { pubkey, tags, created_at: createdAt, locked } = event;
const contentTags = removeDuplicates(getTagsValues("t", tags)).filter(
Boolean,
);
2023-10-14 18:57:37 -04:00
return (
2023-10-20 15:26:55 -04:00
<Card className="relative flex h-full w-full flex-col overflow-hidden @container">
2023-10-14 18:57:37 -04:00
<CardHeader className="flex flex-row items-center justify-between space-y-0 p-4 pb-4">
2023-10-20 15:26:55 -04:00
{pubkey ? (
<ProfileHeader pubkey={pubkey} locked={locked} />
) : (
<LoadingProfileHeader />
)}
2023-10-14 18:57:37 -04:00
<div className="-mr-1 flex items-center gap-x-1.5 text-xs text-muted-foreground">
2023-10-25 15:15:56 -04:00
<span className="line-clamp-1">
{!!createdAt &&
formatDate(new Date(createdAt * 1000), "MMM Do, h:mm a")}
</span>
2023-10-15 11:44:15 -04:00
<DropDownMenu options={actionOptions}>
<Button
size={"sm"}
variant={"ghost"}
className="center h-6 w-6 p-0"
>
<RiMoreFill className="h-4 w-4" />
</Button>
</DropDownMenu>
2023-10-14 18:57:37 -04:00
</div>
</CardHeader>
2023-10-16 00:28:09 -04:00
<CardContent className="flex grow flex-col px-4 pb-3">
2023-10-14 18:57:37 -04:00
{children}
2023-10-16 00:28:09 -04:00
<div className="mt-auto">
2023-10-18 14:14:17 -04:00
{!!contentTags?.length ? (
2023-10-16 11:23:37 -04:00
<div className="mb-2.5 mt-1 max-h-[52px] overflow-hidden">
2023-10-16 00:28:09 -04:00
<Tags tags={contentTags} />
</div>
2023-10-18 14:14:17 -04:00
) : (
<div className="h-1.5" />
2023-10-16 00:28:09 -04:00
)}
2023-10-16 10:59:28 -04:00
<div className="border-t">
<Actions event={event} />
2023-10-16 10:59:28 -04:00
</div>
2023-10-16 00:28:09 -04:00
</div>
2023-10-14 18:57:37 -04:00
</CardContent>
</Card>
);
}