Spaces:
Sleeping
Sleeping
Download apps/web/src/components/tasks/TasksBoard.tsx from Benaah/MicProtocol: direct link, hf CLI and curl.
- Browser
- Download file 9.92 kB
-
https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/web/src/components/tasks/TasksBoard.tsx
- Command line
-
hf download hf://spaces/Benaah/MicProtocol/apps/web/src/components/tasks/TasksBoard.tsx
-
curl -L -o TasksBoard.tsx https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/web/src/components/tasks/TasksBoard.tsx
9.92 kB
| "use client"; | |
| import { useState } from "react"; | |
| import { trpc } from "@/lib/trpc"; | |
| import { formatTime, clsx } from "@/lib/utils"; | |
| import { | |
| TaskStatus, | |
| TaskPriority, | |
| ConversationType, | |
| } from "@micprotocol/shared-types"; | |
| export interface TasksBoardProps { | |
| workspaceId: string; | |
| podcastId?: string; | |
| episodeId?: string; | |
| conversations?: Array<{ id: string; title: string }>; | |
| style?: React.CSSProperties; | |
| } | |
| const COLUMNS: Array<{ status: TaskStatus; label: string; accent: string }> = [ | |
| { status: TaskStatus.TODO, label: "To do", accent: "border-zinc-400" }, | |
| { status: TaskStatus.IN_PROGRESS, label: "In progress", accent: "border-blue-400" }, | |
| { status: TaskStatus.IN_REVIEW, label: "In review", accent: "border-amber-400" }, | |
| { status: TaskStatus.DONE, label: "Done", accent: "border-emerald-400" }, | |
| ]; | |
| export function TasksBoard(props: TasksBoardProps) { | |
| const utils = trpc.useUtils(); | |
| const [newTask, setNewTask] = useState(""); | |
| const [newTaskConv, setNewTaskConv] = useState<string | undefined>( | |
| props.conversations?.[0]?.id, | |
| ); | |
| const list = (trpc.tasks.list.useQuery as any)({ | |
| ...(props.podcastId ? { podcastId: props.podcastId } : {}), | |
| ...(props.episodeId ? { episodeId: props.episodeId } : {}), | |
| }); | |
| type TaskItem = { | |
| id: string; | |
| title: string; | |
| description?: string | null; | |
| status: string; | |
| priority: string; | |
| mediaTimestampSeconds?: string | null; | |
| assignee?: { email?: string | null } | null; | |
| }; | |
| const ensure = trpc.chat.ensureConversation.useMutation(); | |
| const create = trpc.tasks.create.useMutation({ | |
| onSuccess: () => utils.tasks.list.invalidate(), | |
| }); | |
| const update = trpc.tasks.update.useMutation({ | |
| onSuccess: () => utils.tasks.list.invalidate(), | |
| }); | |
| const tasks: TaskItem[] = list.data ?? []; | |
| const grouped = COLUMNS.reduce<Record<string, TaskItem[]>>( | |
| (acc, col) => { | |
| acc[col.status] = tasks.filter((t: TaskItem) => t.status === col.status); | |
| return acc; | |
| }, | |
| {} as Record<string, TaskItem[]>, | |
| ); | |
| return ( | |
| <div className="flex h-full flex-col" style={props.style}> | |
| <header className="flex items-center justify-between border-b px-4 py-3 dark:border-zinc-800"> | |
| <h2 className="text-sm font-semibold">Tasks</h2> | |
| <span className="text-xs text-zinc-500">{tasks.length} total</span> | |
| </header> | |
| <div className="flex flex-wrap items-center gap-2 border-b p-3 dark:border-zinc-800"> | |
| <input | |
| value={newTask} | |
| onChange={(e) => setNewTask(e.target.value)} | |
| placeholder="New task title..." | |
| className="min-w-0 flex-1 rounded-md border bg-transparent px-3 py-2 text-sm outline-none focus:ring-2 focus:ring-blue-500 dark:border-zinc-800" | |
| /> | |
| {props.conversations && props.conversations.length > 0 && ( | |
| <select | |
| value={newTaskConv} | |
| onChange={(e) => setNewTaskConv(e.target.value)} | |
| className="rounded-md border bg-transparent px-2 py-2 text-sm dark:border-zinc-800" | |
| > | |
| {props.conversations.map((c) => ( | |
| <option key={c.id} value={c.id}> | |
| in {c.title} | |
| </option> | |
| ))} | |
| </select> | |
| )} | |
| <button | |
| onClick={async () => { | |
| if (!newTask.trim()) return; | |
| let conversationId = newTaskConv; | |
| if (!conversationId && props.episodeId) { | |
| const c = await ensure.mutateAsync({ | |
| type: ConversationType.EPISODE, | |
| episodeId: props.episodeId, | |
| podcastId: props.podcastId, | |
| }); | |
| conversationId = c.id; | |
| } | |
| create.mutate({ | |
| title: newTask.trim(), | |
| ...(props.episodeId ? { episodeId: props.episodeId } : {}), | |
| ...(props.podcastId ? { podcastId: props.podcastId } : {}), | |
| ...(conversationId ? { conversationId } : {}), | |
| }); | |
| setNewTask(""); | |
| }} | |
| disabled={!newTask.trim() || create.isPending} | |
| className="rounded-md bg-blue-600 px-3 py-2 text-xs font-medium text-white disabled:cursor-not-allowed disabled:bg-zinc-300" | |
| > | |
| Add task | |
| </button> | |
| </div> | |
| <div className="flex flex-1 gap-3 overflow-x-auto p-3"> | |
| {COLUMNS.map((col) => ( | |
| <div | |
| key={col.status} | |
| className={clsx( | |
| "flex w-72 shrink-0 flex-col rounded-lg border-t-2 bg-zinc-50 dark:bg-zinc-900", | |
| col.accent, | |
| )} | |
| > | |
| <header className="flex items-center justify-between px-3 py-2 text-xs font-semibold uppercase tracking-wide text-zinc-500"> | |
| <span>{col.label}</span> | |
| <span>{grouped[col.status].length}</span> | |
| </header> | |
| <div className="flex-1 space-y-2 p-2"> | |
| {grouped[col.status].map((t: TaskItem) => ( | |
| <article | |
| key={t.id} | |
| className="rounded-md border bg-white p-2 text-sm shadow-sm dark:border-zinc-800 dark:bg-zinc-950" | |
| > | |
| <div className="flex items-start justify-between gap-2"> | |
| <h4 className="font-medium leading-snug">{t.title}</h4> | |
| <PriorityBadge p={t.priority as TaskPriority} /> | |
| </div> | |
| {t.description && ( | |
| <p className="mt-1 text-xs text-zinc-500">{t.description}</p> | |
| )} | |
| <div className="mt-2 flex items-center justify-between text-[10px] text-zinc-400"> | |
| <span> | |
| {t.assignee?.email?.split("@")[0] ?? "unassigned"} | |
| </span> | |
| {t.mediaTimestampSeconds != null && ( | |
| <span className="rounded bg-amber-100 px-1.5 py-0.5 text-amber-800 dark:bg-amber-900/30 dark:text-amber-200"> | |
| {formatTime(Number(t.mediaTimestampSeconds))} | |
| </span> | |
| )} | |
| </div> | |
| <div className="mt-2 flex flex-wrap gap-1"> | |
| {nextStatuses(t.status as TaskStatus).map((s) => ( | |
| <button | |
| key={s} | |
| onClick={() => | |
| update.mutate({ | |
| id: t.id, | |
| patch: { status: s }, | |
| }) | |
| } | |
| className="rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-zinc-500 hover:bg-zinc-100 dark:border-zinc-800 dark:hover:bg-zinc-800" | |
| > | |
| {`→ ${labelFor(s)}`} | |
| </button> | |
| ))} | |
| </div> | |
| </article> | |
| ))} | |
| </div> | |
| </div> | |
| ))} | |
| </div> | |
| </div> | |
| ); | |
| } | |
| function nextStatuses(s: TaskStatus): TaskStatus[] { | |
| switch (s) { | |
| case TaskStatus.TODO: return [TaskStatus.IN_PROGRESS, TaskStatus.CANCELLED]; | |
| case TaskStatus.IN_PROGRESS: return [TaskStatus.IN_REVIEW, TaskStatus.DONE]; | |
| case TaskStatus.IN_REVIEW: return [TaskStatus.DONE, TaskStatus.IN_PROGRESS]; | |
| case TaskStatus.DONE: return []; | |
| case TaskStatus.CANCELLED: return [TaskStatus.TODO]; | |
| } | |
| } | |
| function labelFor(s: TaskStatus): string { | |
| return s.replace(/_/g, " "); | |
| } | |
| function priorityLabel(p: TaskPriority): string { | |
| return p.replace(/_/g, " "); | |
| } | |
| function PriorityBadge({ p }: { p: TaskPriority }) { | |
| const styles = | |
| p === TaskPriority.URGENT | |
| ? "bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-200" | |
| : p === TaskPriority.HIGH | |
| ? "bg-orange-100 text-orange-800 dark:bg-orange-900/30 dark:text-orange-200" | |
| : p === TaskPriority.MEDIUM | |
| ? "bg-zinc-100 text-zinc-700 dark:bg-zinc-800 dark:text-zinc-200" | |
| : "bg-zinc-50 text-zinc-500 dark:bg-zinc-900 dark:text-zinc-400"; | |
| return ( | |
| <span className={clsx("rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wide", styles)}> | |
| {priorityLabel(p)} | |
| </span> | |
| ); | |
| } | |