|
|
@ -1,91 +1,168 @@
|
|
|
|
import NextImage from "next/image";
|
|
|
|
import NextImage from "next/image";
|
|
|
|
import Link from "next/link";
|
|
|
|
import NextLink from "next/link";
|
|
|
|
import { useMemo } from "react";
|
|
|
|
import { useMemo } from "react";
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
|
|
|
FiCopy as CopyIcon,
|
|
|
|
|
|
|
|
FiLink as LinkIcon,
|
|
|
|
|
|
|
|
FiYoutube as YoutubeIcon
|
|
|
|
|
|
|
|
} from "react-icons/fi";
|
|
|
|
|
|
|
|
|
|
|
|
import { Card, CardBody, CardFooter } from "@nextui-org/card";
|
|
|
|
import { Card, CardBody, CardFooter } from "@nextui-org/card";
|
|
|
|
import { Divider } from "@nextui-org/divider";
|
|
|
|
import { Divider } from "@nextui-org/divider";
|
|
|
|
import { Image } from "@nextui-org/image";
|
|
|
|
import { Image } from "@nextui-org/image";
|
|
|
|
|
|
|
|
import { Link } from "@nextui-org/link";
|
|
|
|
import { Tooltip } from "@nextui-org/tooltip";
|
|
|
|
import { Tooltip } from "@nextui-org/tooltip";
|
|
|
|
|
|
|
|
|
|
|
|
import { Video as VideoProps } from "@/client/typings/video";
|
|
|
|
import { Video as VideoProps } from "@/client/typings/video";
|
|
|
|
import formatBigNumber from "@/utils/formatBigNumber";
|
|
|
|
import formatBigNumber from "@/utils/formatBigNumber";
|
|
|
|
import formatDuration from "@/utils/formatDuration";
|
|
|
|
import formatDuration from "@/utils/formatDuration";
|
|
|
|
import formatUploadedTime from "@/utils/formatUploadedTime";
|
|
|
|
import formatUploadedTime from "@/utils/formatUploadedTime";
|
|
|
|
import { channelUrl, videoUrl } from "@/utils/urls";
|
|
|
|
import {
|
|
|
|
|
|
|
|
channelUrl,
|
|
|
|
|
|
|
|
videoUrl,
|
|
|
|
|
|
|
|
youtubeChannelUrl,
|
|
|
|
|
|
|
|
youtubeVideoUrl
|
|
|
|
|
|
|
|
} from "@/utils/urls";
|
|
|
|
import { videoSize } from "@/utils/videoSize";
|
|
|
|
import { videoSize } from "@/utils/videoSize";
|
|
|
|
|
|
|
|
|
|
|
|
import { ContextMenu } from "./ContextMenu";
|
|
|
|
import { ContextMenu } from "./ContextMenu";
|
|
|
|
|
|
|
|
|
|
|
|
import { Component } from "@/typings/component";
|
|
|
|
import { Component } from "@/typings/component";
|
|
|
|
import { ContextMenuItem } from "@/typings/contextMenu";
|
|
|
|
import { ContextMenuItem, ContextMenuItemType } from "@/typings/contextMenu";
|
|
|
|
|
|
|
|
|
|
|
|
export const Video: Component<{ data: VideoProps; size?: number }> = ({
|
|
|
|
export const Video: Component<{ data: VideoProps; size?: number }> = ({
|
|
|
|
data,
|
|
|
|
data,
|
|
|
|
size = 40
|
|
|
|
size = 40
|
|
|
|
}) => {
|
|
|
|
}) => {
|
|
|
|
const url = videoUrl(data.id);
|
|
|
|
const url = videoUrl(data.id);
|
|
|
|
|
|
|
|
const channel = data.author.id ? channelUrl(data.author.id) : "#";
|
|
|
|
|
|
|
|
|
|
|
|
const [width, height] = videoSize(size);
|
|
|
|
const [width, height] = videoSize(size);
|
|
|
|
|
|
|
|
|
|
|
|
const menuItems = useMemo(() => {
|
|
|
|
const menuItems = useMemo(() => {
|
|
|
|
|
|
|
|
const hasAuthor = !!data.author.id;
|
|
|
|
|
|
|
|
|
|
|
|
const items: ContextMenuItem[] = [
|
|
|
|
const items: ContextMenuItem[] = [
|
|
|
|
{ title: "Go to video", key: "gotoVideo", href: url },
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
type: ContextMenuItemType.Category,
|
|
|
|
|
|
|
|
title: "Video",
|
|
|
|
|
|
|
|
showDivider: true,
|
|
|
|
|
|
|
|
key: "video",
|
|
|
|
|
|
|
|
items: [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
type: ContextMenuItemType.Action,
|
|
|
|
|
|
|
|
title: "Go to video",
|
|
|
|
|
|
|
|
description: "Opens in this tab",
|
|
|
|
|
|
|
|
icon: <LinkIcon />,
|
|
|
|
|
|
|
|
key: "goToVideo",
|
|
|
|
|
|
|
|
href: url
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
type: ContextMenuItemType.Action,
|
|
|
|
title: "Copy video id",
|
|
|
|
title: "Copy video id",
|
|
|
|
|
|
|
|
icon: <CopyIcon />,
|
|
|
|
key: "videoId",
|
|
|
|
key: "videoId",
|
|
|
|
onClick: (): void => {
|
|
|
|
onClick: (): void => {
|
|
|
|
navigator.clipboard.writeText(data.id);
|
|
|
|
navigator.clipboard.writeText(data.id);
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
showDivider: true
|
|
|
|
{
|
|
|
|
|
|
|
|
type: ContextMenuItemType.Action,
|
|
|
|
|
|
|
|
title: "Copy YouTube video url",
|
|
|
|
|
|
|
|
icon: <YoutubeIcon />,
|
|
|
|
|
|
|
|
key: "youtubeUrl",
|
|
|
|
|
|
|
|
onClick: (): void => {
|
|
|
|
|
|
|
|
const url = youtubeVideoUrl(data.id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
navigator.clipboard.writeText(url.toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
type: ContextMenuItemType.Category,
|
|
|
|
|
|
|
|
title: "Thumbnail",
|
|
|
|
|
|
|
|
showDivider: hasAuthor,
|
|
|
|
|
|
|
|
key: "thumbnail",
|
|
|
|
|
|
|
|
items: [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
type: ContextMenuItemType.Action,
|
|
|
|
title: "Open thumbnail",
|
|
|
|
title: "Open thumbnail",
|
|
|
|
|
|
|
|
description: "Opens in this tab",
|
|
|
|
|
|
|
|
icon: <LinkIcon />,
|
|
|
|
key: "thumbnail",
|
|
|
|
key: "thumbnail",
|
|
|
|
href: data.thumbnail
|
|
|
|
href: data.thumbnail
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
type: ContextMenuItemType.Action,
|
|
|
|
title: "Copy thumnail url",
|
|
|
|
title: "Copy thumnail url",
|
|
|
|
|
|
|
|
icon: <CopyIcon />,
|
|
|
|
key: "thumbnailUrl",
|
|
|
|
key: "thumbnailUrl",
|
|
|
|
onClick: (): void => {
|
|
|
|
onClick: (): void => {
|
|
|
|
navigator.clipboard.writeText(data.thumbnail);
|
|
|
|
navigator.clipboard.writeText(data.thumbnail);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
showDivider: true
|
|
|
|
}
|
|
|
|
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
if (data.author.id) {
|
|
|
|
if (data.author.id)
|
|
|
|
items.push({
|
|
|
|
items.push({
|
|
|
|
|
|
|
|
type: ContextMenuItemType.Category,
|
|
|
|
|
|
|
|
title: "Channel",
|
|
|
|
|
|
|
|
key: "channel",
|
|
|
|
|
|
|
|
items: [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
type: ContextMenuItemType.Action,
|
|
|
|
title: "Go to channel",
|
|
|
|
title: "Go to channel",
|
|
|
|
key: "gotoChannel",
|
|
|
|
description: "Opens in this tab",
|
|
|
|
href: channelUrl(data.author.id)
|
|
|
|
icon: <LinkIcon />,
|
|
|
|
});
|
|
|
|
key: "goToChannel",
|
|
|
|
|
|
|
|
href: channel
|
|
|
|
items.push({
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
type: ContextMenuItemType.Action,
|
|
|
|
title: "Copy channel id",
|
|
|
|
title: "Copy channel id",
|
|
|
|
|
|
|
|
icon: <CopyIcon />,
|
|
|
|
key: "channelId",
|
|
|
|
key: "channelId",
|
|
|
|
onClick: (): void => {
|
|
|
|
onClick: (): void => {
|
|
|
|
navigator.clipboard.writeText(data.author.id ?? "");
|
|
|
|
if (data.author.id) navigator.clipboard.writeText(data.author.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
type: ContextMenuItemType.Action,
|
|
|
|
|
|
|
|
title: "Copy YouTube channel url",
|
|
|
|
|
|
|
|
icon: <YoutubeIcon />,
|
|
|
|
|
|
|
|
key: "youtubeUrl",
|
|
|
|
|
|
|
|
onClick: (): void => {
|
|
|
|
|
|
|
|
if (!data.author.id) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const url = youtubeChannelUrl(data.author.id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
navigator.clipboard.writeText(url.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return items;
|
|
|
|
return items;
|
|
|
|
}, [data, url]);
|
|
|
|
}, [data, channel, url]);
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<Link href={url}>
|
|
|
|
|
|
|
|
<ContextMenu menu={menuItems}>
|
|
|
|
<ContextMenu menu={menuItems}>
|
|
|
|
<Card radius="lg">
|
|
|
|
<Card radius="lg" style={{ maxWidth: `${width}px` }}>
|
|
|
|
<CardBody>
|
|
|
|
<CardBody>
|
|
|
|
|
|
|
|
<NextLink href={url}>
|
|
|
|
<Image
|
|
|
|
<Image
|
|
|
|
as={NextImage}
|
|
|
|
as={NextImage}
|
|
|
|
height={height}
|
|
|
|
height={height}
|
|
|
|
width={width}
|
|
|
|
width={width}
|
|
|
|
unoptimized
|
|
|
|
unoptimized
|
|
|
|
alt={data.title}
|
|
|
|
alt={data.title}
|
|
|
|
className="object-contain aspect"
|
|
|
|
className="object-contain"
|
|
|
|
src={data.thumbnail}
|
|
|
|
src={data.thumbnail}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
|
|
|
|
</NextLink>
|
|
|
|
|
|
|
|
|
|
|
|
<p className="text-small rounded-md z-10 absolute bottom-5 right-5 bg-content2 p-1">
|
|
|
|
<p className="text-small rounded-md z-10 absolute bottom-5 right-5 bg-content2 p-1">
|
|
|
|
{formatDuration(data.duration)}
|
|
|
|
{formatDuration(data.duration)}
|
|
|
@ -93,23 +170,35 @@ export const Video: Component<{ data: VideoProps; size?: number }> = ({
|
|
|
|
</CardBody>
|
|
|
|
</CardBody>
|
|
|
|
<Divider />
|
|
|
|
<Divider />
|
|
|
|
<CardFooter>
|
|
|
|
<CardFooter>
|
|
|
|
<div style={{ width }} className="flex flex-col">
|
|
|
|
<div className="flex flex-col">
|
|
|
|
<p title={data.title} className="text-ellipsis overflow-hidden">
|
|
|
|
<div className="flex min-w-0">
|
|
|
|
|
|
|
|
<Link
|
|
|
|
|
|
|
|
as={NextLink}
|
|
|
|
|
|
|
|
href={url}
|
|
|
|
|
|
|
|
title={data.title}
|
|
|
|
|
|
|
|
className="text-ellipsis overflow-hidden whitespace-nowrap text-foreground"
|
|
|
|
|
|
|
|
>
|
|
|
|
{data.title}
|
|
|
|
{data.title}
|
|
|
|
</p>
|
|
|
|
</Link>
|
|
|
|
<div className="flex flex-row gap-2 justify-start text-ellipsis overflow-hidden">
|
|
|
|
</div>
|
|
|
|
<p className="text-small font-semibold tracking-tight text-default-400">
|
|
|
|
<div className="flex flex-row gap-2 min-w-0">
|
|
|
|
|
|
|
|
<Link
|
|
|
|
|
|
|
|
as={NextLink}
|
|
|
|
|
|
|
|
href={channel}
|
|
|
|
|
|
|
|
className="overflow-ellipsis overflow-hidden whitespace-nowrap text-small font-semibold tracking-tight text-default-400 shrink"
|
|
|
|
|
|
|
|
>
|
|
|
|
{data.author.name}
|
|
|
|
{data.author.name}
|
|
|
|
</p>
|
|
|
|
</Link>
|
|
|
|
|
|
|
|
|
|
|
|
{data.uploaded && (
|
|
|
|
{data.uploaded && (
|
|
|
|
<Tooltip showArrow content={data.uploaded.toLocaleString()}>
|
|
|
|
<Tooltip showArrow content={data.uploaded.toLocaleString()}>
|
|
|
|
<p className="text-small tracking-tight text-default-400">
|
|
|
|
<p className="text-small tracking-tight text-default-400 shrink-0">
|
|
|
|
{formatUploadedTime(data.uploaded)}
|
|
|
|
{formatUploadedTime(data.uploaded)}
|
|
|
|
</p>
|
|
|
|
</p>
|
|
|
|
</Tooltip>
|
|
|
|
</Tooltip>
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
<p className="text-small tracking-tight text-default-400">
|
|
|
|
<p className="text-small tracking-tight text-default-400 shrink-0">
|
|
|
|
Views: {formatBigNumber(data.views)}
|
|
|
|
Views: {formatBigNumber(data.views)}
|
|
|
|
</p>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
@ -117,6 +206,5 @@ export const Video: Component<{ data: VideoProps; size?: number }> = ({
|
|
|
|
</CardFooter>
|
|
|
|
</CardFooter>
|
|
|
|
</Card>
|
|
|
|
</Card>
|
|
|
|
</ContextMenu>
|
|
|
|
</ContextMenu>
|
|
|
|
</Link>
|
|
|
|
|
|
|
|
);
|
|
|
|
);
|
|
|
|
};
|
|
|
|
};
|
|
|
|