From ceeac7fcae3ab35278b139ce57534369da03e217 Mon Sep 17 00:00:00 2001 From: danloh Date: Tue, 27 Feb 2024 20:53:32 -0800 Subject: [PATCH] fix: confirm before delete --- src/components/kanban/Board.tsx | 109 +++++++++++++++++++--------- src/components/kanban/Column.tsx | 9 +-- src/components/kanban/types.ts | 1 + src/components/sidebar/SideMenu.tsx | 2 +- 4 files changed, 81 insertions(+), 40 deletions(-) diff --git a/src/components/kanban/Board.tsx b/src/components/kanban/Board.tsx index 062b31f7..df8d1a55 100644 --- a/src/components/kanban/Board.tsx +++ b/src/components/kanban/Board.tsx @@ -13,7 +13,7 @@ import { } from "@dnd-kit/core"; import { SortableContext, arrayMove } from "@dnd-kit/sortable"; import { createPortal } from "react-dom"; -import { IconPlus } from "@tabler/icons-react"; +import { IconCircle, IconPlus } from "@tabler/icons-react"; import { genId } from "utils/helper"; import { openFilePath } from "file/open"; import { BaseModal } from "components/settings/BaseModal"; @@ -100,14 +100,22 @@ export default function KanbanBoard({initData, onKanbanChange}: Props) { onKanbanChange(newColumns, tasks); } - function deleteColumn(id: Id) { - const filteredColumns = columns.filter((col) => col.id !== id); + const [showDelColumn, setShowDelColumn] = useState(false); + const [toDelColumn, setToDelColumn] = useState(null); + function openDelColumn(id: Id) { + setToDelColumn(id); + setShowDelColumn(true); + } + + function deleteColumn() { + const filteredColumns = columns.filter((col) => col.id !== toDelColumn); setColumns(filteredColumns); - const newTasks = tasks.filter((t) => t.columnId !== id); + const newTasks = tasks.filter((t) => t.columnId !== toDelColumn); setTasks(newTasks); // save to file onKanbanChange(filteredColumns, newTasks); + setShowDelColumn(false); } function updateColumn(id: Id, title: string) { @@ -228,6 +236,8 @@ export default function KanbanBoard({initData, onKanbanChange}: Props) { if (col.id !== id) return col; if (ty === "bg") { return { ...col, bgColor: color }; + } else if (ty === "head") { + return { ...col, hdColor: color }; } else { return { ...col, ftColor: color }; } @@ -277,7 +287,7 @@ export default function KanbanBoard({initData, onKanbanChange}: Props) { setIsColSetting(false)} >
-
- Background Color - {setColumnColor(colSetting?.id || "", "bg", e.target.value)} } - /> -
-
- Font Color - {setColumnColor(colSetting?.id || "", "ft", e.target.value)} } - /> -
+
Set Color
+
Set Color
-
- Background Color - {setCardColor(cardSetting?.id || "", "bg", e.target.value)} } - /> -
-
- Font Color - {setCardColor(cardSetting?.id || "", "ft", e.target.value)} } - /> -
+ + +
+ setShowDelColumn(false)} + > +
+ +
); } + +type SetProps = { + id: Id; + setColor: (id: Id, ty: string, color: string) => void; +} + +function SetColor({id, setColor} : SetProps) { + const colors = [ + "rgb(220 38 38)", "rgb(245 158 11)", "rgb(21 128 61)", + "rgb(14 165 233)", "rgb(79 70 229)", "rgb(124 58 237)", + ]; + const [selectedTy, setSelectedTy] = useState("bg"); + + return ( +
+ + {colors.map((color, index) => ( + + ))} + {setColor(id, selectedTy, e.target.value);}} + /> +
+ ); +} diff --git a/src/components/kanban/Column.tsx b/src/components/kanban/Column.tsx index 613f3516..849975a5 100644 --- a/src/components/kanban/Column.tsx +++ b/src/components/kanban/Column.tsx @@ -5,10 +5,9 @@ import { IconPlus, IconTool, IconTrash } from "@tabler/icons-react"; import { Column, Id, Card } from "./types"; import TaskCard from "./Card"; - interface Props { column: Column; - deleteColumn: (id: Id) => void; + toDelColumn: (id: Id) => void; updateColumn: (id: Id, title: string) => void; createTask: (columnId: Id) => void; updateTask: (id: Id, content: string) => void; @@ -20,7 +19,7 @@ interface Props { export default function ColumnContainer({ column, - deleteColumn, + toDelColumn, updateColumn, createTask, tasks, @@ -82,7 +81,7 @@ export default function ColumnContainer({ onMouseEnter={() => {setMouseIsOver(true);}} onMouseLeave={() => {setMouseIsOver(false);}} className="p-2 mb-2 text-lg h-[60px] cursor-grab rounded-md font-bold flex items-center justify-between" - style={{color: column.ftColor || "white"}} + style={{color: column.ftColor || "white", backgroundColor: column.hdColor || ""}} >
{!editMode && column.title} @@ -103,7 +102,7 @@ export default function ColumnContainer({ {mouseIsOver && (