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-12 15:15:22 +00:00
|
|
|
import { ArrowUpDown, MoreHorizontal } from "lucide-react"
|
|
|
|
import { Button } from "@/components/ui/button"
|
2024-06-19 11:14:12 +00:00
|
|
|
import { Badge } from "@/components/ui/badge"
|
2024-06-19 19:58:19 +00:00
|
|
|
import { Trash2 } from "lucide-react"
|
2024-06-19 16:01:42 +00:00
|
|
|
import { deleteStory } from "app/lib/del"
|
2024-06-19 11:14:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
const columnHelper = createColumnHelper<StoryWithGenres>()
|
|
|
|
|
2024-06-19 16:01:42 +00:00
|
|
|
|
2024-06-19 11:14:12 +00:00
|
|
|
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()
|
|
|
|
.map(e => <Badge>{e.name}</Badge>)
|
|
|
|
return genres
|
|
|
|
}
|
2024-06-19 16:01:42 +00:00
|
|
|
}),
|
|
|
|
{
|
|
|
|
id: "actions",
|
|
|
|
header: "Actions",
|
|
|
|
cell: ({ row }) => {
|
|
|
|
return <Button variant="ghost"
|
|
|
|
onClick={() => { deleteStory(row.original.id) }}>
|
2024-06-19 19:58:19 +00:00
|
|
|
<Trash2 color="red" /></Button>
|
2024-06-19 16:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-12 15:15:22 +00:00
|
|
|
|
|
|
|
]
|
|
|
|
|