From 06a9cbafc2eeeeed55c283cefa192500d5c0b67d Mon Sep 17 00:00:00 2001 From: saki Date: Fri, 29 Mar 2024 10:21:14 +0900 Subject: [PATCH] add deleting board command --- src/components/TheCommandPalette.tsx | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/components/TheCommandPalette.tsx b/src/components/TheCommandPalette.tsx index fabd3c7..94be6d9 100644 --- a/src/components/TheCommandPalette.tsx +++ b/src/components/TheCommandPalette.tsx @@ -7,6 +7,11 @@ import { v4 as uuidv4 } from 'uuid' import { showBoardDialog, showCommandPalette } from "../main" import { State } from "../types/state" import { Board } from "../types/board" +import { RepositoryLocalStorage } from "../repositories/repository" +import { ApplicationService } from "../applications/applicationService" + +const repository = new RepositoryLocalStorage() +const service = new ApplicationService(repository) type Command = { id: string @@ -61,6 +66,23 @@ export default function TheCommandPalette({ appState }: { appState: Signal { + return boards.map(b => { + return { + id: uuidv4(), + label: `Delete board: ${b.name}`, + action: () => { + // TODO: refactor + if (window.confirm(`Do you really want to delete board: ${b.name}`)) { + showCommandPalette.value = false + const updated = service.deleteBoard(appState.value, b.id) + appState.value = updated + } + } + } + }) + } + const buildCommandsForCards = (board: Board): Command[] => { return board.lists.flatMap(l => { return l.cards.map(c => { @@ -81,7 +103,8 @@ export default function TheCommandPalette({ appState }: { appState: Signal buildCommandsForCards(b)), - commandBoardCreate + commandBoardCreate, + ...buildCommandsBoardDelete(boards) ] }