subman-nextjs/src/app/story/columns.tsx

77 lines
2.1 KiB
TypeScript
Raw Normal View History

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-09-21 15:23:31 +00:00
import { ArrowUpDown, BookType, Drama, Tally5 } from "lucide-react"
2024-06-12 15:15:22 +00:00
import { Button } from "@/components/ui/button"
2024-06-20 18:02:25 +00:00
import GenreBadges from "app/ui/genreBadges"
2024-06-30 11:36:13 +00:00
import { selectCol } from "app/ui/tables/selectColumn"
import NumberInputCell from "app/ui/tables/inputs/numberInput"
2024-09-19 09:37:01 +00:00
import { storySchema } from "app/ui/forms/schemas"
2024-07-02 21:01:26 +00:00
import { TextInputCell } from "app/ui/tables/inputs/textInput"
2024-07-23 15:40:35 +00:00
import GenrePickerInputCell from "app/ui/tables/inputs/genrePickerInput"
2024-06-19 11:14:12 +00:00
const columnHelper = createColumnHelper<StoryWithGenres>()
export const columns: ColumnDef<StoryWithGenres>[] = [
2024-06-30 11:36:13 +00:00
selectCol,
2024-06-12 15:15:22 +00:00
{
accessorKey: "title",
header: ({ column }) => {
return (
<Button
variant="ghost"
2024-09-21 15:23:31 +00:00
className="px-1"
2024-06-12 15:15:22 +00:00
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
>
2024-09-21 15:23:31 +00:00
<span className="hidden sm:block">
Title
</span>
<span className="display-block sm:hidden"><BookType /></span>
2024-06-12 15:15:22 +00:00
<ArrowUpDown className="ml-2 h-4 w-4" />
</Button>
)
},
cell: TextInputCell,
2024-09-19 09:37:01 +00:00
meta: { formSchema: storySchema }
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"
2024-09-21 15:23:31 +00:00
className="px-1"
2024-06-19 09:34:45 +00:00
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
>
2024-09-21 15:23:31 +00:00
<span className="hidden sm:block">
Word Count
</span>
<span className="sm:hidden">
<Tally5 />
</span>
2024-06-19 09:34:45 +00:00
<ArrowUpDown className="ml-2 h-4 w-4" />
</Button>
)
},
2024-06-30 21:22:46 +00:00
enableColumnFilter: false,
cell: NumberInputCell,
2024-06-30 21:22:46 +00:00
meta: {
step: 50,
2024-09-19 09:37:01 +00:00
formSchema: storySchema
2024-06-30 21:22:46 +00:00
}
2024-06-19 09:34:45 +00:00
},
2024-06-19 11:14:12 +00:00
columnHelper.accessor("genres", {
2024-09-21 15:23:31 +00:00
header: () => (
<div className="w-fit mx-auto">
<span className="hidden sm:block">Genres</span>
<span className="sm:hidden"><Drama /></span>
</div>
),
2024-07-23 15:40:35 +00:00
cell: GenrePickerInputCell,
filterFn: "arrIncludes",
meta: {}
}),
2024-06-30 21:22:46 +00:00
2024-06-12 15:15:22 +00:00
]