2024-03-22 16:13:10 +00:00
|
|
|
import { TrashIcon } from "@radix-ui/react-icons";
|
|
|
|
import type { ColumnDef } from "@tanstack/react-table";
|
2024-03-27 06:22:58 +00:00
|
|
|
import { DownloadIcon, FileIcon, MoreIcon } from "~/components/icons";
|
2024-03-12 03:41:05 +00:00
|
|
|
import { Checkbox } from "~/components/ui/checkbox";
|
2024-03-21 05:17:00 +00:00
|
|
|
import {
|
|
|
|
DropdownMenu,
|
|
|
|
DropdownMenuContent,
|
|
|
|
DropdownMenuGroup,
|
|
|
|
DropdownMenuItem,
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
} from "~/components/ui/dropdown-menu";
|
|
|
|
|
2024-03-18 19:51:02 +00:00
|
|
|
import { cn } from "~/utils";
|
2024-03-22 12:47:50 +00:00
|
|
|
import type { FileItem } from "~/data/file-provider";
|
2024-03-26 13:42:18 +00:00
|
|
|
import { usePinning } from "~/hooks/usePinning";
|
2024-03-27 06:02:21 +00:00
|
|
|
import filesize from "~/components/lib/filesize";
|
2024-03-27 06:22:58 +00:00
|
|
|
import { Button } from "~/components/ui/button";
|
2024-03-27 10:05:48 +00:00
|
|
|
import {useSdk} from "~/components/lib/sdk-context.js";
|
|
|
|
import {S5Client} from "@lumeweb/s5-js";
|
|
|
|
import {PROTOCOL_S5} from "@lumeweb/portal-sdk";
|
2024-03-27 06:02:21 +00:00
|
|
|
|
2024-03-12 03:41:05 +00:00
|
|
|
|
|
|
|
// This type is used to define the shape of our data.
|
|
|
|
// You can use a Zod schema here if you want.
|
|
|
|
export type File = {
|
2024-03-21 05:17:00 +00:00
|
|
|
name: string;
|
|
|
|
cid: string;
|
|
|
|
size: string;
|
|
|
|
createdOn: string;
|
2024-03-12 03:41:05 +00:00
|
|
|
};
|
|
|
|
|
2024-03-21 20:46:02 +00:00
|
|
|
export const columns: ColumnDef<FileItem>[] = [
|
2024-03-27 06:34:52 +00:00
|
|
|
// {
|
|
|
|
// id: "select",
|
|
|
|
// size: 20,
|
|
|
|
// header: ({ table }) => (
|
|
|
|
// <Checkbox
|
|
|
|
// checked={
|
|
|
|
// table.getIsAllPageRowsSelected() ||
|
|
|
|
// (table.getIsSomePageRowsSelected() && "indeterminate")
|
|
|
|
// }
|
|
|
|
// onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
|
|
|
|
// aria-label="Select all"
|
|
|
|
// />
|
|
|
|
// ),
|
|
|
|
// cell: ({ row }) => (
|
|
|
|
// <Checkbox
|
|
|
|
// checked={row.getIsSelected()}
|
|
|
|
// onCheckedChange={(value) => row.toggleSelected(!!value)}
|
|
|
|
// aria-label="Select row"
|
|
|
|
// />
|
|
|
|
// ),
|
|
|
|
// enableSorting: false,
|
|
|
|
// enableHiding: false,
|
|
|
|
// },
|
2024-03-28 22:59:11 +00:00
|
|
|
{
|
|
|
|
accessorKey: "name",
|
|
|
|
header: () => null,
|
|
|
|
},
|
2024-03-21 05:17:00 +00:00
|
|
|
{
|
2024-03-27 06:22:58 +00:00
|
|
|
accessorKey: "cid",
|
|
|
|
header: "CID",
|
2024-03-21 05:17:00 +00:00
|
|
|
cell: ({ row }) => (
|
|
|
|
<div className="flex items-center gap-x-2">
|
|
|
|
<FileIcon />
|
2024-03-27 06:22:58 +00:00
|
|
|
{row.getValue("name") ?? row.getValue("cid")}
|
2024-03-21 05:17:00 +00:00
|
|
|
</div>
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
accessorKey: "size",
|
|
|
|
header: "Size",
|
2024-03-27 06:02:21 +00:00
|
|
|
cell: ({ row }) => {
|
|
|
|
const size = row.getValue("size");
|
|
|
|
return size ? filesize(size as number, 2) : "";
|
|
|
|
},
|
2024-03-21 05:17:00 +00:00
|
|
|
},
|
|
|
|
{
|
2024-03-22 12:47:50 +00:00
|
|
|
accessorKey: "pinned",
|
|
|
|
header: "Pinned On",
|
|
|
|
cell: ({ row }) => new Date(row.getValue("pinned")).toLocaleString(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
accessorKey: "actions",
|
|
|
|
header: () => null,
|
|
|
|
size: 20,
|
2024-03-26 13:42:18 +00:00
|
|
|
cell: ({ row }) => {
|
2024-03-26 14:54:51 +00:00
|
|
|
const { unpin } = usePinning();
|
2024-03-27 10:05:48 +00:00
|
|
|
const sdk = useSdk();
|
2024-03-27 06:22:58 +00:00
|
|
|
const downloadFile = () => {
|
|
|
|
const cid = row.getValue("cid");
|
2024-03-27 10:05:48 +00:00
|
|
|
const portalUrl = sdk.protocols!().get<S5Client>(PROTOCOL_S5).getSdk().portalUrl;
|
|
|
|
|
|
|
|
window.open(`${portalUrl}/s5/download/${cid}`,"_blank");
|
2024-03-27 06:22:58 +00:00
|
|
|
};
|
2024-03-26 13:42:18 +00:00
|
|
|
return (
|
2024-03-27 06:22:58 +00:00
|
|
|
<div className="flex space-x-2 w-10 items-center justify-between">
|
|
|
|
<Button size={"icon"} variant="ghost" onClick={downloadFile}>
|
|
|
|
<DownloadIcon className="w-5"/>
|
|
|
|
</Button>
|
2024-03-26 14:54:51 +00:00
|
|
|
<DropdownMenu>
|
|
|
|
<DropdownMenuTrigger
|
|
|
|
className={cn(
|
2024-03-27 06:22:58 +00:00
|
|
|
"opacity-0 group-hover:opacity-100 data-[state=open]:opacity-100",
|
2024-03-26 14:54:51 +00:00
|
|
|
row.getIsSelected() && "block",
|
|
|
|
)}>
|
|
|
|
<MoreIcon />
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent align="end">
|
|
|
|
<DropdownMenuGroup>
|
|
|
|
<DropdownMenuItem
|
|
|
|
variant="destructive"
|
|
|
|
onClick={() => {
|
|
|
|
unpin(row.getValue("cid"));
|
|
|
|
}}>
|
|
|
|
<TrashIcon className="mr-2" />
|
|
|
|
Delete
|
|
|
|
</DropdownMenuItem>
|
|
|
|
</DropdownMenuGroup>
|
|
|
|
</DropdownMenuContent>
|
|
|
|
</DropdownMenu>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
2024-03-21 05:17:00 +00:00
|
|
|
},
|
|
|
|
];
|