70 lines
2.7 KiB
TypeScript
70 lines
2.7 KiB
TypeScript
import { addTask, removeTask, setStatus } from './actions';
|
|
import { dbHealth } from '@/lib/db';
|
|
import { buildInfo } from '@/lib/build-info';
|
|
import { listTasks, STATUSES, type Status } from '@/lib/tasks';
|
|
|
|
// Always render per request: the board is live data, and the footer shows the running build.
|
|
export const dynamic = 'force-dynamic';
|
|
|
|
const TITLES: Record<Status, string> = { todo: 'To do', doing: 'In progress', done: 'Done' };
|
|
const bootedAt = new Date().toISOString();
|
|
|
|
export default async function Home() {
|
|
const [tasks, health] = await Promise.all([listTasks().catch(() => null), dbHealth()]);
|
|
|
|
return (
|
|
<main>
|
|
<header>
|
|
<h1>Taskboard</h1>
|
|
<span className={`pill ${health.status}`}>DB {health.status}</span>
|
|
</header>
|
|
|
|
<form action={addTask} className="add">
|
|
<input name="title" placeholder="New task…" maxLength={200} required />
|
|
<input name="assignee" placeholder="Assignee (optional)" maxLength={80} />
|
|
<button type="submit">Add</button>
|
|
</form>
|
|
|
|
{tasks === null ? (
|
|
<p className="error">Could not load tasks. Check the database connection.</p>
|
|
) : (
|
|
<div className="board">
|
|
{STATUSES.map((s) => (
|
|
<section key={s}>
|
|
<h2>
|
|
{TITLES[s]} <span className="count">{tasks.filter((t) => t.status === s).length}</span>
|
|
</h2>
|
|
{tasks
|
|
.filter((t) => t.status === s)
|
|
.map((t) => (
|
|
<article key={t.id}>
|
|
<strong>{t.title}</strong>
|
|
{t.assignee && <small>@{t.assignee}</small>}
|
|
<div className="actions">
|
|
{STATUSES.filter((x) => x !== s).map((x) => (
|
|
<form action={setStatus} key={x}>
|
|
<input type="hidden" name="id" value={t.id} />
|
|
<input type="hidden" name="status" value={x} />
|
|
<button className="secondary">→ {TITLES[x]}</button>
|
|
</form>
|
|
))}
|
|
<form action={removeTask}>
|
|
<input type="hidden" name="id" value={t.id} />
|
|
<button className="danger" aria-label={`Delete ${t.title}`}>✕</button>
|
|
</form>
|
|
</div>
|
|
</article>
|
|
))}
|
|
</section>
|
|
))}
|
|
</div>
|
|
)}
|
|
|
|
<footer data-testid="build-info">
|
|
Build <b>v{buildInfo.version}</b> · commit <b>{buildInfo.commit ?? 'n/a'}</b> · source{' '}
|
|
<b>{buildInfo.sourceHash}</b> · built {buildInfo.builtAt} · server started {bootedAt}
|
|
</footer>
|
|
</main>
|
|
);
|
|
}
|