Skip to content

Commit

Permalink
Merge pull request #128 from sakihet/add-deleting-board-command
Browse files Browse the repository at this point in the history
add deleting board command
  • Loading branch information
sakihet authored Mar 29, 2024
2 parents f7f5b2d + 06a9cba commit 3a275c0
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/components/TheCommandPalette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -61,6 +66,23 @@ export default function TheCommandPalette({ appState }: { appState: Signal<State
}
}

const buildCommandsBoardDelete = (boards: Board[]): Command[] => {
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 => {
Expand All @@ -81,7 +103,8 @@ export default function TheCommandPalette({ appState }: { appState: Signal<State
...commandsDefault,
...buildCommandsForBoards(boards),
...boards.flatMap(b => buildCommandsForCards(b)),
commandBoardCreate
commandBoardCreate,
...buildCommandsBoardDelete(boards)
]
}

Expand Down

0 comments on commit 3a275c0

Please sign in to comment.