Download references/shared-task-card/src/components/TaskRow.tsx from mirasim-ai/devbrowse-bench: direct link, hf CLI and curl.
- Browser
- Download file 2.81 kB
-
https://huggingface.co/datasets/mirasim-ai/devbrowse-bench/resolve/main/references/shared-task-card/src/components/TaskRow.tsx
- Command line
-
hf download hf://datasets/mirasim-ai/devbrowse-bench/references/shared-task-card/src/components/TaskRow.tsx
-
curl -L -o TaskRow.tsx https://huggingface.co/datasets/mirasim-ai/devbrowse-bench/resolve/main/references/shared-task-card/src/components/TaskRow.tsx
2.81 kB
| import { useState } from "react"; | |
| import { Link } from "react-router-dom"; | |
| import { useTasks } from "../store/TasksContext"; | |
| import { useToast } from "../store/ToastContext"; | |
| import type { Task } from "../types"; | |
| import { ConfirmDialog } from "./ConfirmDialog"; | |
| import { EditTaskDialog } from "./EditTaskDialog"; | |
| import { PriorityBadge } from "./PriorityBadge"; | |
| /** One task, as a row of the task list or as a card on the Board, with its Edit and Delete dialogs. */ | |
| export function TaskRow({ task, variant = "row" }: { task: Task; variant?: "row" | "card" }) { | |
| const { updateTask, toggleDone, deleteTask } = useTasks(); | |
| const toast = useToast(); | |
| const [editing, setEditing] = useState(false); | |
| const [deleting, setDeleting] = useState(false); | |
| const editDelete = ( | |
| <> | |
| <button onClick={() => setEditing(true)} aria-label={`Edit ${task.title}`}> | |
| Edit | |
| </button> | |
| <button className="danger" onClick={() => setDeleting(true)} aria-label={`Delete ${task.title}`}> | |
| Delete | |
| </button> | |
| </> | |
| ); | |
| return ( | |
| <li className={variant === "card" ? "card" : task.done ? "task done" : "task"} data-task-id={task.id}> | |
| {variant === "row" ? ( | |
| <> | |
| <input type="checkbox" checked={task.done} onChange={() => void toggleDone(task.id)} aria-label={`Complete ${task.title}`} /> | |
| <Link className="title" to={`/tasks/${task.id}`}> | |
| {task.title} | |
| </Link> | |
| <PriorityBadge priority={task.priority} /> | |
| {editDelete} | |
| </> | |
| ) : ( | |
| <> | |
| <Link to={`/tasks/${task.id}`}>{task.title}</Link> | |
| <div className="card-foot"> | |
| <PriorityBadge priority={task.priority} /> | |
| <div className="card-actions"> | |
| <button onClick={() => void toggleDone(task.id)}>{task.done ? "Reopen" : "Mark done"}</button> | |
| {editDelete} | |
| </div> | |
| </div> | |
| </> | |
| )} | |
| {editing && ( | |
| <EditTaskDialog | |
| task={task} | |
| onSave={async (patch) => { | |
| try { | |
| await updateTask(task.id, patch); | |
| setEditing(false); | |
| } catch (e) { | |
| toast((e as Error).message, "error"); | |
| } | |
| }} | |
| onClose={() => setEditing(false)} | |
| /> | |
| )} | |
| {deleting && ( | |
| <ConfirmDialog | |
| title="Delete task?" | |
| message={`"${task.title}" will be deleted for everyone on the team.`} | |
| confirmLabel="Delete" | |
| onCancel={() => setDeleting(false)} | |
| onConfirm={async () => { | |
| setDeleting(false); | |
| try { | |
| await deleteTask(task.id); | |
| } catch (e) { | |
| toast((e as Error).message, "error"); | |
| } | |
| }} | |
| /> | |
| )} | |
| </li> | |
| ); | |
| } | |