Skip to content

Commit

Permalink
fixed delete board error
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-Web3 committed May 13, 2023
1 parent 4030028 commit 74e4a67
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/shared/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const NavBar: React.FC<{
variants={boardVariants}
key={idx}
className={`navbar__board ${
board.id === currentBoard.id ? 'active' : ''
board.id === currentBoard?.id ? 'active' : ''
}`}
onClick={() => setCurrentBoard(board.id)}
>
Expand Down
6 changes: 5 additions & 1 deletion src/components/store/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@ const useStore = create<State & Action>()(
| 'normal',
deleteBoard: function (boardId) {
const newBoards = get().boards.filter(board => board.id !== boardId)
let adjacentBoardIdx = get().boards.findIndex(
board => board.id === boardId
)
adjacentBoardIdx = adjacentBoardIdx > 0 ? adjacentBoardIdx - 1 : 0

set(() => ({ boards: newBoards }))
get().setCurrentBoard(0)
get().setCurrentBoard(get().boards[adjacentBoardIdx]?.id || 0)
get().setModalType({ modalType: '', showModal: false })
},
deleteTask: function (boardId, taskId) {
Expand Down

0 comments on commit 74e4a67

Please sign in to comment.