feat(ui): add upload to IAIDndImage

Add uploading to IAIDndImage
- add `postUploadAction` arg to `imageUploaded` thunk, with several current valid options (set control image, set init, set nodes image, set canvas, or toast)
- updated IAIDndImage to optionally allow click to upload
This commit is contained in:
psychedelicious
2023-06-07 00:38:22 +10:00
parent f223ad7776
commit 58fec84858
12 changed files with 159 additions and 129 deletions

View File

@ -6,11 +6,8 @@ import {
initialImageChanged,
} from 'features/parameters/store/generationSlice';
import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { generationSelector } from 'features/parameters/store/generationSelectors';
import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions';
import { configSelector } from '../../../../system/store/configSelectors';
import { useAppToaster } from 'app/components/Toaster';
import IAIDndImage from 'common/components/IAIDndImage';
import { ImageDTO } from 'services/api';
import { IAIImageFallback } from 'common/components/IAIImageFallback';
@ -28,28 +25,7 @@ const selector = createSelector(
const InitialImagePreview = () => {
const { initialImage } = useAppSelector(selector);
const { shouldFetchImages } = useAppSelector(configSelector);
const dispatch = useAppDispatch();
const { t } = useTranslation();
const toaster = useAppToaster();
const handleError = useCallback(() => {
dispatch(clearInitialImage());
if (shouldFetchImages) {
toaster({
title: 'Something went wrong, please refresh',
status: 'error',
isClosable: true,
});
} else {
toaster({
title: t('toast.parametersFailed'),
description: t('toast.parametersFailedDesc'),
status: 'error',
isClosable: true,
});
}
}, [dispatch, t, toaster, shouldFetchImages]);
const handleDrop = useCallback(
(droppedImage: ImageDTO) => {
@ -81,6 +57,7 @@ const InitialImagePreview = () => {
onDrop={handleDrop}
onReset={handleReset}
fallback={<IAIImageFallback sx={{ bg: 'none' }} />}
postUploadAction={{ type: 'SET_INITIAL_IMAGE' }}
/>
</Flex>
);