-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): handle edge cases when archiving/deleting boards
If the currently selected or auto-add board is archived or deleted, we should reset them. There are some edge cases taht weren't handled in the previous implementation. All handling of this logic is moved to the (renamed) listener.
- Loading branch information
1 parent
037b17e
commit 822017b
Showing
7 changed files
with
52 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...rc/app/store/middleware/listenerMiddleware/listeners/addArchivedOrDeletedBoardListener.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { isAnyOf } from '@reduxjs/toolkit'; | ||
import type { AppStartListening } from 'app/store/middleware/listenerMiddleware'; | ||
import { selectListBoardsQueryArgs } from 'features/gallery/store/gallerySelectors'; | ||
import { | ||
autoAddBoardIdChanged, | ||
boardIdSelected, | ||
galleryViewChanged, | ||
shouldShowArchivedBoardsChanged, | ||
} from 'features/gallery/store/gallerySlice'; | ||
import { boardsApi } from 'services/api/endpoints/boards'; | ||
import { imagesApi } from 'services/api/endpoints/images'; | ||
|
||
export const addArchivedOrDeletedBoardListener = (startAppListening: AppStartListening) => { | ||
startAppListening({ | ||
matcher: isAnyOf( | ||
// Updating a board may change its archived status | ||
boardsApi.endpoints.updateBoard.matchFulfilled, | ||
// If the selected/auto-add board was deleted from a different session, we'll only know during the list request, | ||
boardsApi.endpoints.listAllBoards.matchFulfilled, | ||
// If a board is deleted, we'll need to reset the auto-add board | ||
imagesApi.endpoints.deleteBoard.matchFulfilled, | ||
imagesApi.endpoints.deleteBoardAndImages.matchFulfilled, | ||
// When we change the visibility of archived boards, we may need to reset the auto-add board | ||
shouldShowArchivedBoardsChanged | ||
), | ||
effect: async (action, { dispatch, getState }) => { | ||
/** | ||
* The auto-add board shouldn't be set to an archived board or deleted board. When we archive a board, delete | ||
* a board, or change a the archived board visibility flag, we may need to reset the auto-add board. | ||
*/ | ||
|
||
const state = getState(); | ||
const queryArgs = selectListBoardsQueryArgs(state); | ||
const queryResult = boardsApi.endpoints.listAllBoards.select(queryArgs)(state); | ||
const autoAddBoardId = state.gallery.autoAddBoardId; | ||
|
||
if (!queryResult.data) { | ||
return; | ||
} | ||
|
||
if (!queryResult.data.find((board) => board.board_id === autoAddBoardId)) { | ||
dispatch(autoAddBoardIdChanged('none')); | ||
dispatch(boardIdSelected({ boardId: 'none' })); | ||
dispatch(galleryViewChanged('images')); | ||
} | ||
}, | ||
}); | ||
}; |
25 changes: 0 additions & 25 deletions
25
...end/web/src/app/store/middleware/listenerMiddleware/listeners/checkAutoAddBoardVisible.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters