2024-03-15 20:00:25 +00:00
|
|
|
import { DrawingPinIcon, TrashIcon } from "@radix-ui/react-icons";
|
|
|
|
import type { ColumnDef, RowData } from "@tanstack/react-table";
|
2024-03-13 17:01:23 +00:00
|
|
|
import { FileIcon, MoreIcon } from "~/components/icons";
|
2024-03-12 03:41:05 +00:00
|
|
|
import { Checkbox } from "~/components/ui/checkbox";
|
2024-03-15 20:00:25 +00:00
|
|
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "~/components/ui/dropdown-menu";
|
2024-03-18 19:51:02 +00:00
|
|
|
import { cn } from "~/utils";
|
2024-03-21 20:46:02 +00:00
|
|
|
import {FileItem} from "~/data/file-provider.js";
|
|
|
|
import {format} from "date-fns/fp";
|
2024-03-12 03:41:05 +00:00
|
|
|
|
2024-03-15 20:00:25 +00:00
|
|
|
declare module '@tanstack/table-core' {
|
|
|
|
interface TableMeta<TData extends RowData> {
|
|
|
|
hoveredRowId: string,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-21 20:46:02 +00:00
|
|
|
export const columns: ColumnDef<FileItem>[] = [
|
2024-03-12 03:41:05 +00:00
|
|
|
{
|
|
|
|
id: "select",
|
2024-03-15 20:00:25 +00:00
|
|
|
size: 20,
|
2024-03-12 03:41:05 +00:00
|
|
|
header: ({ table }) => (
|
|
|
|
<Checkbox
|
2024-03-21 20:46:02 +00:00
|
|
|
|
2024-03-12 03:41:05 +00:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
accessorKey: "name",
|
|
|
|
header: "Name",
|
|
|
|
cell: ({ row }) => (
|
|
|
|
<div className="flex items-center gap-x-2">
|
|
|
|
<FileIcon />
|
|
|
|
{row.getValue("name")}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
accessorKey: "cid",
|
|
|
|
header: "CID",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
accessorKey: "size",
|
|
|
|
header: "Size",
|
|
|
|
},
|
|
|
|
{
|
2024-03-21 20:46:02 +00:00
|
|
|
accessorKey: "pinnedOn",
|
2024-03-15 20:00:25 +00:00
|
|
|
size: 200,
|
2024-03-21 20:46:02 +00:00
|
|
|
header: "Pinned On",
|
2024-03-18 19:51:02 +00:00
|
|
|
cell: ({ row }) => (
|
2024-03-12 03:41:05 +00:00
|
|
|
<div className="flex items-center justify-between">
|
2024-03-21 20:46:02 +00:00
|
|
|
{format(row.getValue("pinned")) as unknown as string}
|
2024-03-15 20:00:25 +00:00
|
|
|
<DropdownMenu>
|
2024-03-18 19:51:02 +00:00
|
|
|
<DropdownMenuTrigger className={
|
|
|
|
cn("hidden group-hover:block data-[state=open]:block", row.getIsSelected() && "block")
|
|
|
|
}>
|
2024-03-15 20:00:25 +00:00
|
|
|
<MoreIcon />
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent align="end">
|
|
|
|
<DropdownMenuGroup>
|
|
|
|
<DropdownMenuItem>
|
|
|
|
<DrawingPinIcon className="mr-2" />
|
|
|
|
Ping CID
|
|
|
|
</DropdownMenuItem>
|
|
|
|
<DropdownMenuSeparator />
|
|
|
|
<DropdownMenuItem variant="destructive">
|
|
|
|
<TrashIcon className="mr-2" />
|
|
|
|
Delete
|
|
|
|
</DropdownMenuItem>
|
|
|
|
</DropdownMenuGroup>
|
|
|
|
</DropdownMenuContent>
|
|
|
|
</DropdownMenu>
|
2024-03-12 03:41:05 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2024-03-21 20:46:02 +00:00
|
|
|
];
|