block auto add board change during generation. Switch condition to isProcessing

This commit is contained in:
Kevin Brack 2023-07-31 19:34:24 -05:00 committed by psychedelicious
parent 366952f810
commit 87424be95d
4 changed files with 26 additions and 20 deletions

View File

@ -11,11 +11,14 @@ import { useListAllBoardsQuery } from 'services/api/endpoints/boards';
const selector = createSelector( const selector = createSelector(
[stateSelector], [stateSelector],
({ gallery }) => { ({ gallery, system }) => {
const { autoAddBoardId } = gallery; const { autoAddBoardId, autoAssignBoardOnClick } = gallery;
const { isProcessing } = system;
return { return {
autoAddBoardId, autoAddBoardId,
autoAssignBoardOnClick,
isProcessing,
}; };
}, },
defaultSelectorOptions defaultSelectorOptions
@ -23,7 +26,8 @@ const selector = createSelector(
const BoardAutoAddSelect = () => { const BoardAutoAddSelect = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { autoAddBoardId } = useAppSelector(selector); const { autoAddBoardId, autoAssignBoardOnClick, isProcessing } =
useAppSelector(selector);
const inputRef = useRef<HTMLInputElement>(null); const inputRef = useRef<HTMLInputElement>(null);
const { boards, hasBoards } = useListAllBoardsQuery(undefined, { const { boards, hasBoards } = useListAllBoardsQuery(undefined, {
selectFromResult: ({ data }) => { selectFromResult: ({ data }) => {
@ -67,7 +71,7 @@ const BoardAutoAddSelect = () => {
data={boards} data={boards}
nothingFound="No matching Boards" nothingFound="No matching Boards"
itemComponent={IAIMantineSelectItemWithTooltip} itemComponent={IAIMantineSelectItemWithTooltip}
disabled={!hasBoards} disabled={!hasBoards || autoAssignBoardOnClick || isProcessing}
filter={(value, item: SelectItem) => filter={(value, item: SelectItem) =>
item.label?.toLowerCase().includes(value.toLowerCase().trim()) || item.label?.toLowerCase().includes(value.toLowerCase().trim()) ||
item.value.toLowerCase().includes(value.toLowerCase().trim()) item.value.toLowerCase().includes(value.toLowerCase().trim())

View File

@ -27,7 +27,6 @@ import { useGetImageDTOQuery } from 'services/api/endpoints/images';
import { BoardDTO } from 'services/api/types'; import { BoardDTO } from 'services/api/types';
import AutoAddIcon from '../AutoAddIcon'; import AutoAddIcon from '../AutoAddIcon';
import BoardContextMenu from '../BoardContextMenu'; import BoardContextMenu from '../BoardContextMenu';
import { useIsReadyToInvoke } from 'common/hooks/useIsReadyToInvoke';
interface GalleryBoardProps { interface GalleryBoardProps {
board: BoardDTO; board: BoardDTO;
@ -42,19 +41,24 @@ const GalleryBoard = memo(
() => () =>
createSelector( createSelector(
stateSelector, stateSelector,
({ gallery }) => { ({ gallery, system }) => {
const isSelectedForAutoAdd = const isSelectedForAutoAdd =
board.board_id === gallery.autoAddBoardId; board.board_id === gallery.autoAddBoardId;
const autoAssignBoardOnClick = gallery.autoAssignBoardOnClick; const autoAssignBoardOnClick = gallery.autoAssignBoardOnClick;
const isProcessing = system.isProcessing;
return { isSelectedForAutoAdd, autoAssignBoardOnClick }; return {
isSelectedForAutoAdd,
autoAssignBoardOnClick,
isProcessing,
};
}, },
defaultSelectorOptions defaultSelectorOptions
), ),
[board.board_id] [board.board_id]
); );
const { isSelectedForAutoAdd, autoAssignBoardOnClick } = const { isSelectedForAutoAdd, autoAssignBoardOnClick, isProcessing } =
useAppSelector(selector); useAppSelector(selector);
const [isHovered, setIsHovered] = useState(false); const [isHovered, setIsHovered] = useState(false);
const handleMouseOver = useCallback(() => { const handleMouseOver = useCallback(() => {
@ -70,14 +74,12 @@ const GalleryBoard = memo(
const { board_name, board_id } = board; const { board_name, board_id } = board;
const [localBoardName, setLocalBoardName] = useState(board_name); const [localBoardName, setLocalBoardName] = useState(board_name);
const isReady = useIsReadyToInvoke();
const handleSelectBoard = useCallback(() => { const handleSelectBoard = useCallback(() => {
dispatch(boardIdSelected(board_id)); dispatch(boardIdSelected(board_id));
if (autoAssignBoardOnClick && isReady) { if (autoAssignBoardOnClick && !isProcessing) {
dispatch(autoAddBoardIdChanged(board_id)); dispatch(autoAddBoardIdChanged(board_id));
} }
}, [board_id, autoAssignBoardOnClick, isReady, dispatch]); }, [board_id, autoAssignBoardOnClick, isProcessing, dispatch]);
const [updateBoard, { isLoading: isUpdateBoardLoading }] = const [updateBoard, { isLoading: isUpdateBoardLoading }] =
useUpdateBoardMutation(); useUpdateBoardMutation();

View File

@ -15,31 +15,31 @@ import { memo, useCallback, useMemo, useState } from 'react';
import { useBoardName } from 'services/api/hooks/useBoardName'; import { useBoardName } from 'services/api/hooks/useBoardName';
import AutoAddIcon from '../AutoAddIcon'; import AutoAddIcon from '../AutoAddIcon';
import BoardContextMenu from '../BoardContextMenu'; import BoardContextMenu from '../BoardContextMenu';
import { useIsReadyToInvoke } from 'common/hooks/useIsReadyToInvoke';
interface Props { interface Props {
isSelected: boolean; isSelected: boolean;
} }
const selector = createSelector( const selector = createSelector(
stateSelector, stateSelector,
({ gallery }) => { ({ gallery, system }) => {
const { autoAddBoardId, autoAssignBoardOnClick } = gallery; const { autoAddBoardId, autoAssignBoardOnClick } = gallery;
return { autoAddBoardId, autoAssignBoardOnClick }; const { isProcessing } = system;
return { autoAddBoardId, autoAssignBoardOnClick, isProcessing };
}, },
defaultSelectorOptions defaultSelectorOptions
); );
const NoBoardBoard = memo(({ isSelected }: Props) => { const NoBoardBoard = memo(({ isSelected }: Props) => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { autoAddBoardId, autoAssignBoardOnClick } = useAppSelector(selector); const { autoAddBoardId, autoAssignBoardOnClick, isProcessing } =
useAppSelector(selector);
const boardName = useBoardName(undefined); const boardName = useBoardName(undefined);
const isReady = useIsReadyToInvoke();
const handleSelectBoard = useCallback(() => { const handleSelectBoard = useCallback(() => {
dispatch(boardIdSelected(undefined)); dispatch(boardIdSelected(undefined));
if (autoAssignBoardOnClick && isReady) { if (autoAssignBoardOnClick && !isProcessing) {
dispatch(autoAddBoardIdChanged(undefined)); dispatch(autoAddBoardIdChanged(undefined));
} }
}, [dispatch, autoAssignBoardOnClick, isReady]); }, [dispatch, autoAssignBoardOnClick, isProcessing]);
const [isHovered, setIsHovered] = useState(false); const [isHovered, setIsHovered] = useState(false);
const handleMouseOver = useCallback(() => { const handleMouseOver = useCallback(() => {
setIsHovered(true); setIsHovered(true);

View File

@ -82,7 +82,7 @@ const GallerySettingsPopover = () => {
dispatch(autoAssignBoardOnClickChanged(e.target.checked)) dispatch(autoAssignBoardOnClickChanged(e.target.checked))
} }
/> />
{!autoAssignBoardOnClick && <BoardAutoAddSelect />} <BoardAutoAddSelect />
</Flex> </Flex>
</IAIPopover> </IAIPopover>
); );