fix(ui): fix control image save button logic

This commit is contained in:
psychedelicious 2023-08-30 11:33:38 +10:00
parent 33cb6cb4d8
commit 8982543312

View File

@ -18,6 +18,7 @@ import {
useAddImageToBoardMutation, useAddImageToBoardMutation,
useChangeImageIsIntermediateMutation, useChangeImageIsIntermediateMutation,
useGetImageDTOQuery, useGetImageDTOQuery,
useRemoveImageFromBoardMutation,
} from 'services/api/endpoints/images'; } from 'services/api/endpoints/images';
import { PostUploadAction } from 'services/api/types'; import { PostUploadAction } from 'services/api/types';
import IAIDndImageIcon from '../../../common/components/IAIDndImageIcon'; import IAIDndImageIcon from '../../../common/components/IAIDndImageIcon';
@ -71,23 +72,36 @@ const ControlNetImagePreview = ({ isSmall, controlNet }: Props) => {
const [changeIsIntermediate] = useChangeImageIsIntermediateMutation(); const [changeIsIntermediate] = useChangeImageIsIntermediateMutation();
const [addToBoard] = useAddImageToBoardMutation(); const [addToBoard] = useAddImageToBoardMutation();
const [removeFromBoard] = useRemoveImageFromBoardMutation();
const handleResetControlImage = useCallback(() => { const handleResetControlImage = useCallback(() => {
dispatch(controlNetImageChanged({ controlNetId, controlImage: null })); dispatch(controlNetImageChanged({ controlNetId, controlImage: null }));
}, [controlNetId, dispatch]); }, [controlNetId, dispatch]);
const handleSaveControlImage = useCallback(() => { const handleSaveControlImage = useCallback(async () => {
if (!processedControlImage) { if (!processedControlImage) {
return; return;
} }
changeIsIntermediate({ await changeIsIntermediate({
imageDTO: processedControlImage, imageDTO: processedControlImage,
is_intermediate: false, is_intermediate: false,
}); }).unwrap();
addToBoard({ imageDTO: processedControlImage, board_id: autoAddBoardId }); if (autoAddBoardId !== 'none') {
}, [processedControlImage, autoAddBoardId, changeIsIntermediate, addToBoard]); addToBoard({
imageDTO: processedControlImage,
board_id: autoAddBoardId,
});
} else {
removeFromBoard({ imageDTO: processedControlImage });
}
}, [
processedControlImage,
changeIsIntermediate,
autoAddBoardId,
addToBoard,
removeFromBoard,
]);
const handleSetControlImageToDimensions = useCallback(() => { const handleSetControlImageToDimensions = useCallback(() => {
if (!processedControlImage) { if (!processedControlImage) {