chore: scaffold turbo monorepo with hono api and react admin web
This commit is contained in:
131
apps/web/src/routes/_authenticated/tasks.tsx
Normal file
131
apps/web/src/routes/_authenticated/tasks.tsx
Normal file
@@ -0,0 +1,131 @@
|
||||
import {
|
||||
createColumnHelper,
|
||||
tableFeatures,
|
||||
useTable,
|
||||
} from '@tanstack/react-table'
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
import { SearchIcon } from 'lucide-react'
|
||||
import { useMemo, useState } from 'react'
|
||||
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from '@/components/ui/table'
|
||||
|
||||
export const Route = createFileRoute('/_authenticated/tasks')({
|
||||
component: TasksPage,
|
||||
})
|
||||
|
||||
type Task = {
|
||||
title: string
|
||||
list: string
|
||||
status: 'todo' | 'in progress' | 'done'
|
||||
priority: 'low' | 'medium' | 'high'
|
||||
}
|
||||
|
||||
const TASKS: Task[] = [
|
||||
{ title: 'Design onboarding flow', list: 'Q4 roadmap', status: 'in progress', priority: 'high' },
|
||||
{ title: 'Write API docs', list: 'Docs', status: 'todo', priority: 'medium' },
|
||||
{ title: 'Review Prisma migrations', list: 'Backend', status: 'todo', priority: 'high' },
|
||||
{ title: 'Ship dark mode', list: 'Design system', status: 'done', priority: 'low' },
|
||||
{ title: 'Migrate to Turborepo', list: 'Infra', status: 'done', priority: 'medium' },
|
||||
{ title: 'Add e2e smoke test', list: 'Quality', status: 'in progress', priority: 'low' },
|
||||
]
|
||||
|
||||
// `tableFeatures` and the columns live at module scope so row models stay stable.
|
||||
const features = tableFeatures({})
|
||||
const columnHelper = createColumnHelper<typeof features, Task>()
|
||||
|
||||
const columns = columnHelper.columns([
|
||||
columnHelper.accessor('title', { header: 'Task' }),
|
||||
columnHelper.accessor('list', { header: 'List' }),
|
||||
columnHelper.accessor('status', { header: 'Status' }),
|
||||
columnHelper.accessor('priority', { header: 'Priority' }),
|
||||
])
|
||||
|
||||
const STATUS_VARIANT = {
|
||||
todo: 'outline',
|
||||
'in progress': 'secondary',
|
||||
done: 'default',
|
||||
} as const
|
||||
|
||||
function TasksPage() {
|
||||
const [query, setQuery] = useState('')
|
||||
|
||||
const data = useMemo(
|
||||
() =>
|
||||
TASKS.filter((task) =>
|
||||
`${task.title} ${task.list} ${task.status}`.toLowerCase().includes(query.toLowerCase()),
|
||||
),
|
||||
[query],
|
||||
)
|
||||
|
||||
const table = useTable({ features, columns, data })
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Tasks</CardTitle>
|
||||
<CardDescription>Every task across your lists.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
<div className="relative max-w-sm">
|
||||
<SearchIcon className="text-muted-foreground absolute top-2.5 left-2.5 size-4" />
|
||||
<Input
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
placeholder="Filter tasks…"
|
||||
className="pl-8"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="rounded-md border">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
{table.getHeaderGroups().map((headerGroup) => (
|
||||
<TableRow key={headerGroup.id}>
|
||||
{headerGroup.headers.map((header) => (
|
||||
<TableHead key={header.id}>
|
||||
{header.isPlaceholder ? null : <table.FlexRender header={header} />}
|
||||
</TableHead>
|
||||
))}
|
||||
</TableRow>
|
||||
))}
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{table.getRowModel().rows.length === 0 && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={columns.length} className="text-muted-foreground h-24 text-center">
|
||||
No tasks match your filter.
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
{table.getRowModel().rows.map((row) => (
|
||||
<TableRow key={row.id}>
|
||||
{row.getAllCells().map((cell) => (
|
||||
<TableCell key={cell.id}>
|
||||
{cell.column.id === 'status' ? (
|
||||
<Badge variant={STATUS_VARIANT[cell.getValue<Task['status']>()]}>
|
||||
{cell.getValue<Task['status']>()}
|
||||
</Badge>
|
||||
) : (
|
||||
<table.FlexRender cell={cell} />
|
||||
)}
|
||||
</TableCell>
|
||||
))}
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user