2024-06-12 15:15:22 +00:00
|
|
|
"use client"
|
2024-06-19 11:14:12 +00:00
|
|
|
import { ColumnDef, createColumnHelper } from "@tanstack/react-table"
|
|
|
|
import { StoryWithGenres } from "./page"
|
2024-06-20 09:39:35 +00:00
|
|
|
import { ArrowUpDown } from "lucide-react"
|
2024-06-12 15:15:22 +00:00
|
|
|
import { Button } from "@/components/ui/button"
|
2024-06-19 11:14:12 +00:00
|
|
|
import { Badge } from "@/components/ui/badge"
|
2024-06-19 20:11:09 +00:00
|
|
|
import { Trash2, Search } from "lucide-react"
|
2024-06-19 21:21:51 +00:00
|
|
|
import {
|
|
|
|
Dialog,
|
|
|
|
DialogContent,
|
|
|
|
DialogDescription,
|
|
|
|
DialogFooter,
|
|
|
|
DialogHeader,
|
|
|
|
DialogTitle,
|
|
|
|
DialogTrigger,
|
|
|
|
} from "@/components/ui/dialog"
|
2024-06-19 16:01:42 +00:00
|
|
|
import { deleteStory } from "app/lib/del"
|
2024-06-19 20:11:09 +00:00
|
|
|
import Link from "next/link"
|
2024-06-20 09:39:35 +00:00
|
|
|
import { DialogClose } from "@radix-ui/react-dialog"
|
2024-06-20 18:02:25 +00:00
|
|
|
import GenreBadges from "app/ui/genreBadges"
|
2024-06-19 11:14:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
const columnHelper = createColumnHelper<StoryWithGenres>()
|
|
|
|
|
|
|
|
export const columns: ColumnDef<StoryWithGenres>[] = [
|
2024-06-12 15:15:22 +00:00
|
|
|
{
|
|
|
|
accessorKey: "title",
|
|
|
|
header: ({ column }) => {
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
variant="ghost"
|
|
|
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
|
|
|
>
|
|
|
|
Title
|
|
|
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
|
|
|
</Button>
|
|
|
|
)
|
|
|
|
},
|
2024-06-19 09:34:45 +00:00
|
|
|
|
2024-06-12 15:15:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
accessorKey: "word_count",
|
2024-06-19 09:34:45 +00:00
|
|
|
header: ({ column }) => {
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
variant="ghost"
|
|
|
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
|
|
|
>
|
|
|
|
Word Count
|
|
|
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
|
|
|
</Button>
|
|
|
|
)
|
|
|
|
},
|
|
|
|
enableColumnFilter: false
|
|
|
|
},
|
2024-06-19 11:14:12 +00:00
|
|
|
columnHelper.accessor("genres", {
|
|
|
|
cell: props => {
|
|
|
|
const genres = props.getValue()
|
2024-06-20 18:02:25 +00:00
|
|
|
return <GenreBadges genres={genres} />
|
2024-06-19 21:51:55 +00:00
|
|
|
},
|
|
|
|
filterFn: "arrIncludes"
|
|
|
|
//TODO - write custom filter function, to account for an array of objects
|
2024-06-19 16:01:42 +00:00
|
|
|
}),
|
|
|
|
{
|
|
|
|
id: "actions",
|
2024-06-19 20:11:09 +00:00
|
|
|
// header: "Actions",
|
2024-06-19 16:01:42 +00:00
|
|
|
cell: ({ row }) => {
|
2024-06-19 20:11:09 +00:00
|
|
|
return <div className="flex items-center justify-around">
|
|
|
|
<Link href={`/story/${row.original.id}`}><Search /></Link>
|
2024-06-19 21:21:51 +00:00
|
|
|
<Dialog>
|
|
|
|
<DialogTrigger asChild>
|
|
|
|
<Button variant="ghost"><Trash2 color="red" /></Button>
|
|
|
|
</DialogTrigger>
|
|
|
|
<DialogContent>
|
|
|
|
<DialogHeader>
|
|
|
|
<DialogTitle>Are you sure?</DialogTitle>
|
|
|
|
<DialogDescription>
|
|
|
|
Deleting a story cannot be undone!
|
|
|
|
</DialogDescription>
|
|
|
|
</DialogHeader>
|
|
|
|
<DialogFooter>
|
2024-06-20 09:39:35 +00:00
|
|
|
<DialogClose asChild>
|
|
|
|
<Button variant="destructive"
|
|
|
|
onClick={() => {
|
|
|
|
deleteStory(row.original.id)
|
|
|
|
}}>Yes, delete it!
|
|
|
|
</Button>
|
|
|
|
</DialogClose>
|
2024-06-19 21:21:51 +00:00
|
|
|
</DialogFooter>
|
|
|
|
</DialogContent>
|
|
|
|
</Dialog>
|
2024-06-19 20:11:09 +00:00
|
|
|
</div>
|
2024-06-19 16:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-12 15:15:22 +00:00
|
|
|
|
|
|
|
]
|
|
|
|
|