diff --git a/src/app/workspace/page.tsx b/src/app/workspace/page.tsx index 7cfbf61..0455e3e 100644 --- a/src/app/workspace/page.tsx +++ b/src/app/workspace/page.tsx @@ -1,183 +1,7 @@ "use client"; -import React, { useEffect, useState } from "react"; -import { - Card, - CardHeader, - CardTitle, - CardContent, - CardFooter, - CardDescription, -} from "@/components/ui/card"; -import { Button } from "@/components/ui/button"; -import { Trash } from "lucide-react"; -import { DragDropContext, Droppable, Draggable } from "@hello-pangea/dnd"; -import { Color, getColor } from "@/lib/ui/color"; - -type Task = { - id: string; - title: string; - description?: string; - tags?: { name: string; color: Color }[]; -}; - -const columnLabels: Record = { - todo: "To do", - inprogress: "In progress", - done: "Done", -}; - -const id = (prefix = "t") => - `${prefix}_${Math.random().toString(36).slice(2, 9)}`; +import BoardView from "@/components/view/board/BoardView"; export default function Workspace() { - const [columns, setColumns] = useState>({ - todo: [], - inprogress: [], - done: [], - }); - - useEffect(() => { - setColumns({ - todo: [ - { id: id(), title: "Buy groceries" }, - { id: id(), title: "Plan sprint" }, - ], - inprogress: [ - { - 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" }, - ], - }, - ], - done: [{ id: id(), title: "Set up repo" }], - }); - }, []); - - const [mounted, setMounted] = useState(false); - useEffect(() => setMounted(true), []); - - if (!mounted) return null; - - function onDragEnd(result: any) { - const { source, destination } = result; - if (!destination) return; - - const sourceCol = source.droppableId; - const destCol = destination.droppableId; - - if (sourceCol === destCol) { - const items = Array.from(columns[sourceCol]); - const [moved] = items.splice(source.index, 1); - items.splice(destination.index, 0, moved); - setColumns({ ...columns, [sourceCol]: items }); - } else { - const sourceItems = Array.from(columns[sourceCol]); - const destItems = Array.from(columns[destCol]); - const [moved] = sourceItems.splice(source.index, 1); - destItems.splice(destination.index, 0, moved); - setColumns({ - ...columns, - [sourceCol]: sourceItems, - [destCol]: destItems, - }); - } - } - - return ( -
- -
- {Object.keys(columnLabels).map((colKey) => ( - - {(provided) => ( - - - - {columnLabels[colKey]} - - {columns[colKey].length} - - - - -
- {columns[colKey].map((task, index) => ( - - {(provided) => ( - - - {task.title} - - {task.description} - - - - {task.tags?.map((tag, i) => ( - - {tag.name} - - ))} - - - )} - - ))} - {provided.placeholder} - {columns[colKey].length === 0 && ( -

- No tasks -

- )} -
-
- -
- -
-
-
- )} -
- ))} -
-
-
- ); + return ; } diff --git a/src/components/view/board/BoardView.tsx b/src/components/view/board/BoardView.tsx new file mode 100644 index 0000000..26a7caa --- /dev/null +++ b/src/components/view/board/BoardView.tsx @@ -0,0 +1,163 @@ +"use client"; + +import { useState } from "react"; +import { + Card, + CardHeader, + CardTitle, + CardContent, + CardDescription, +} from "@/components/ui/card"; +import { Button } from "@/components/ui/button"; +import { DragDropContext, Droppable, Draggable } from "@hello-pangea/dnd"; +import { Color, getColor } from "@/lib/ui/color"; +import { PlusIcon } from "lucide-react"; + +type Task = { + id: string; + title: string; + description?: string; + tags?: { name: string; color: Color }[]; +}; + +const columnLabels: Record = { + todo: "To do", + inprogress: "In progress", + done: "Done", +}; + +const id = (prefix = "t") => + `${prefix}_${Math.random().toString(36).slice(2, 9)}`; + +export default function BoardView() { + const [columns, setColumns] = useState>({ + todo: [ + { id: id(), title: "Buy groceries" }, + { id: id(), title: "Plan sprint" }, + ], + inprogress: [ + { + 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" }, + ], + }, + ], + done: [], + }); + + function onDragEnd(result: any) { + const { source, destination } = result; + if (!destination) return; + + const sourceCol = source.droppableId; + const destCol = destination.droppableId; + + if (sourceCol === destCol) { + const items = Array.from(columns[sourceCol]); + const [moved] = items.splice(source.index, 1); + items.splice(destination.index, 0, moved); + setColumns({ ...columns, [sourceCol]: items }); + } else { + const sourceItems = Array.from(columns[sourceCol]); + const destItems = Array.from(columns[destCol]); + const [moved] = sourceItems.splice(source.index, 1); + destItems.splice(destination.index, 0, moved); + setColumns({ + ...columns, + [sourceCol]: sourceItems, + [destCol]: destItems, + }); + } + } + + return ( +
+ +
+ {Object.keys(columnLabels).map((colKey) => ( + + {(provided) => ( + + + + {columnLabels[colKey]} + + + + +
+ {columns[colKey].map((task, index) => ( + + {(provided) => ( + + + {task.title} + + {task.description} + + + + {task.tags?.map((tag, i) => ( + + {tag.name} + + ))} + + + )} + + ))} + {provided.placeholder} + {columns[colKey].length === 0 && ( +

+ No tasks +

+ )} +
+
+
+ )} +
+ ))} +
+
+
+ ); +}