feat: add entry links to Tag template

This commit is contained in:
Thomas Bishop 2025-07-29 17:56:00 +01:00
parent 8ab2aa77a6
commit c098bfc044
2 changed files with 142 additions and 102 deletions

View file

@ -3,7 +3,6 @@ import {
getCoreRowModel, getCoreRowModel,
useReactTable, useReactTable,
getPaginationRowModel, getPaginationRowModel,
SortingState,
getSortedRowModel, getSortedRowModel,
} from "@tanstack/react-table" } from "@tanstack/react-table"

View file

@ -1,7 +1,47 @@
import { useParams } from "react-router" import { useParams } from "react-router"
import Page from "./Page" import Page from "./Page"
import { useQuery } from "@tanstack/react-query"
import api from "@/api/eolas-api"
import { DataTable } from "@/components/DataTable"
import { ArrowUpDown } from "lucide-react"
import { Button } from "@/components/ui/button"
import { Link } from "react-router"
const columns = [
{
accessorKey: "entry_title",
header: ({ column }) => {
return (
<Button
variant="ghost"
className="rounded-none"
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
>
Title
<ArrowUpDown className="ml-2 h-4 w-4" />
</Button>
)
},
cell: ({ cell, row }) => {
return (
<Link to={`/entries/${row.original.entry_title}`}>
<span className="text-foreground underline-offset-3 underline hover:text-gray-700 dark:hover:text-green-300">
{row.original.entry_title.replace(/_/g, " ")}
</span>
</Link>
)
},
},
]
export default function Tag() { export default function Tag() {
const { tag } = useParams() const { tag } = useParams()
const { data, isLoading } = useQuery({
queryKey: [`entries_for_tag_${tag}`],
queryFn: () => api.get(`/entries/tag/${tag}`).then((res) => res.data),
})
return ( return (
<Page <Page
titleComponent={ titleComponent={
@ -10,6 +50,7 @@ export default function Tag() {
<span>{tag}</span> <span>{tag}</span>
</> </>
} }
pageBody={<DataTable columns={columns} data={data?.data || []} loading={isLoading} />}
/> />
) )
} }