diff --git a/src/app/workspace/page.tsx b/src/app/workspace/page.tsx index 0455e3e..9f86ac2 100644 --- a/src/app/workspace/page.tsx +++ b/src/app/workspace/page.tsx @@ -1,7 +1,45 @@ "use client"; import BoardView from "@/components/view/board/BoardView"; +import { Task } from "@/lib/types"; +import { useEffect, useState } from "react"; + +const id = (prefix = "t") => + `${prefix}_${Math.random().toString(36).slice(2, 9)}`; export default function Workspace() { - return ; + const [tasks, setTasks] = useState([]); + + useEffect(() => { + setTasks([ + { id: id(), title: "Buy groceries", status: "todo" }, + { id: id(), title: "Plan sprint", status: "todo" }, + { + id: id(), + title: "Build header", + description: "A simple description", + tags: [ + { name: "Website", color: "pink" }, + { name: "Development", color: "blue" }, + { name: "API", color: "green" }, + { name: "App", color: "purple" }, + { name: "Rust", color: "orange" }, + ], + status: "inprogress", + }, + ]); + }, []); + + const createTask = (status: string) => { + const task: Task = { + id: id(), + title: "New task", + status: status, + }; + setTasks((c) => [...c, task]); + }; + + return ( + + ); } diff --git a/src/components/view/board/BoardView.tsx b/src/components/view/board/BoardView.tsx index a64aaf3..067c962 100644 --- a/src/components/view/board/BoardView.tsx +++ b/src/components/view/board/BoardView.tsx @@ -1,11 +1,10 @@ "use client"; -import { useEffect, useState } from "react"; import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { DragDropContext, Droppable, Draggable } from "@hello-pangea/dnd"; import { PlusIcon } from "lucide-react"; -import { Task } from "@/lib/types"; +import { SetState, Task } from "@/lib/types"; import BoardTask from "./Task"; const columnLabels: Record = { @@ -14,32 +13,15 @@ const columnLabels: Record = { done: "Done", }; -const id = (prefix = "t") => - `${prefix}_${Math.random().toString(36).slice(2, 9)}`; - -export default function BoardView() { - const [tasks, setTasks] = useState([]); - - useEffect(() => { - setTasks([ - { id: id(), title: "Buy groceries", status: "todo" }, - { id: id(), title: "Plan sprint", status: "todo" }, - { - id: id(), - title: "Build header", - description: "A simple description", - tags: [ - { name: "Website", color: "pink" }, - { name: "Development", color: "blue" }, - { name: "API", color: "green" }, - { name: "App", color: "purple" }, - { name: "Rust", color: "orange" }, - ], - status: "inprogress", - }, - ]); - }, []); - +export default function BoardView({ + tasks, + setTasks, + createTask, +}: { + tasks: Task[]; + setTasks: SetState; + createTask: (status: string) => void; +}) { function onDragEnd(result: any) { const { draggableId, source, destination } = result; if (!destination) return; @@ -71,8 +53,8 @@ export default function BoardView() {
- {Object.keys(columnLabels).map((colKey) => ( - + {Object.keys(columnLabels).map((status) => ( + {(provided) => ( - {columnLabels[colKey]} + {columnLabels[status]} @@ -102,7 +77,7 @@ export default function BoardView() {
{tasks - .filter((task) => task.status === colKey) + .filter((task) => task.status === status) .map((task, index) => ( ))} {provided.placeholder} - {tasks.filter((task) => task.status === colKey).length === + {tasks.filter((task) => task.status === status).length === 0 && (

No tasks