feat(ui): select a board when it is created

This commit is contained in:
psychedelicious 2024-07-09 22:37:41 +10:00
parent 060d698a12
commit 6014382c7b
2 changed files with 11 additions and 5 deletions

View File

@ -15,8 +15,6 @@ export const addArchivedOrDeletedBoardListener = (startAppListening: AppStartLis
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,

View File

@ -1,4 +1,6 @@
import { IconButton } from '@invoke-ai/ui-library';
import { useAppDispatch } from 'app/store/storeHooks';
import { boardIdSelected } from 'features/gallery/store/gallerySlice';
import { memo, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { PiPlusBold } from 'react-icons/pi';
@ -10,11 +12,17 @@ type Props = {
const AddBoardButton = ({ isPrivateBoard }: Props) => {
const { t } = useTranslation();
const dispatch = useAppDispatch();
const [createBoard, { isLoading }] = useCreateBoardMutation();
const DEFAULT_BOARD_NAME = t('boards.myBoard');
const handleCreateBoard = useCallback(() => {
createBoard({ board_name: DEFAULT_BOARD_NAME, is_private: isPrivateBoard });
}, [createBoard, DEFAULT_BOARD_NAME, isPrivateBoard]);
const handleCreateBoard = useCallback(async () => {
try {
const board = await createBoard({ board_name: DEFAULT_BOARD_NAME, is_private: isPrivateBoard }).unwrap();
dispatch(boardIdSelected({ boardId: board.board_id }));
} catch {
//no-op
}
}, [createBoard, DEFAULT_BOARD_NAME, isPrivateBoard, dispatch]);
return (
<IconButton