2024-03-15 20:00:25 +00:00
|
|
|
import { DrawingPinIcon, TrashIcon } from "@radix-ui/react-icons";
|
2024-03-21 05:17:00 +00:00
|
|
|
import type { ColumnDef, Row } 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-21 05:17:00 +00:00
|
|
|
import {
|
|
|
|
DropdownMenu,
|
|
|
|
DropdownMenuContent,
|
|
|
|
DropdownMenuGroup,
|
|
|
|
DropdownMenuItem,
|
|
|
|
DropdownMenuSeparator,
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
} from "~/components/ui/dropdown-menu";
|
|
|
|
|
2024-03-22 13:54:46 +00:00
|
|
|
import { usePinning } from "~/hooks/usePinning";
|
2024-03-18 19:51:02 +00:00
|
|
|
import { cn } from "~/utils";
|
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 05:17:00 +00:00
|
|
|
const CreatedOnCell = ({ row }: { row: Row<File> }) => {
|
|
|
|
// const { open } = useNotification();
|
2024-03-22 13:54:46 +00:00
|
|
|
const { mutate } = usePinning();
|
2024-03-21 05:17:00 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
{row.getValue("createdOn")}
|
|
|
|
<DropdownMenu>
|
|
|
|
<DropdownMenuTrigger
|
|
|
|
className={cn(
|
|
|
|
"hidden group-hover:block data-[state=open]:block",
|
|
|
|
row.getIsSelected() && "block",
|
|
|
|
)}>
|
|
|
|
<MoreIcon />
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent align="end">
|
|
|
|
<DropdownMenuGroup>
|
|
|
|
<DropdownMenuItem
|
|
|
|
onClick={() => {
|
|
|
|
console.log(`Adding ${row.getValue("cid")} for pinning...`);
|
2024-03-22 03:15:56 +00:00
|
|
|
mutate({
|
|
|
|
cid: row.getValue("cid"),
|
2024-03-22 13:54:46 +00:00
|
|
|
type: "pin"
|
2024-03-22 03:15:56 +00:00
|
|
|
});
|
2024-03-21 05:17:00 +00:00
|
|
|
}}>
|
|
|
|
<DrawingPinIcon className="mr-2" />
|
2024-03-21 14:56:08 +00:00
|
|
|
Pin CID
|
2024-03-21 05:17:00 +00:00
|
|
|
</DropdownMenuItem>
|
|
|
|
<DropdownMenuSeparator />
|
|
|
|
<DropdownMenuItem variant="destructive">
|
|
|
|
<TrashIcon className="mr-2" />
|
|
|
|
Delete
|
|
|
|
</DropdownMenuItem>
|
|
|
|
</DropdownMenuGroup>
|
|
|
|
</DropdownMenuContent>
|
|
|
|
</DropdownMenu>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
2024-03-15 20:00:25 +00:00
|
|
|
|
2024-03-12 03:41:05 +00:00
|
|
|
export const columns: ColumnDef<File>[] = [
|
2024-03-21 05:17:00 +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,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
accessorKey: "createdOn",
|
|
|
|
size: 200,
|
|
|
|
header: "Created On",
|
|
|
|
cell: ({ row }) => <CreatedOnCell row={row} />,
|
|
|
|
},
|
|
|
|
];
|