From e1e5266fc3133612273a41028ef4d07c7fba63b2 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Mon, 15 May 2023 17:45:05 +1000 Subject: [PATCH] feat(ui): refactor base image uploading logic --- invokeai/frontend/web/public/locales/en.json | 2 +- .../frontend/web/src/app/components/App.tsx | 3 + .../components/AuxiliaryProgressIndicator.tsx | 44 +++++ .../listeners/imageUploaded.ts | 3 + .../web/src/common/components/IAIInput.tsx | 3 +- .../src/common/components/IAINumberInput.tsx | 2 + .../web/src/common/components/IAITextarea.tsx | 9 ++ .../common/components/ImageToImageButtons.tsx | 8 +- .../src/common/components/ImageUploader.tsx | 152 +++++++++--------- .../common/components/ImageUploaderButton.tsx | 11 +- .../components/ImageUploaderIconButton.tsx | 7 +- .../src/common/components/Loading/Loading.tsx | 1 - .../web/src/common/hooks/useImageUploader.ts | 21 ++- .../src/common/util/stopPastePropagation.ts | 5 + .../canvas/components/IAICanvasResizer.tsx | 2 +- .../components/GalleryProgressImage.tsx | 5 +- .../Core/ParamNegativeConditioning.tsx | 5 +- .../Core/ParamPositiveConditioning.tsx | 5 +- .../system/store/systemPersistDenylist.ts | 23 +-- .../src/features/system/store/systemSlice.ts | 24 +++ .../src/features/ui/components/InvokeTabs.tsx | 4 + 21 files changed, 213 insertions(+), 126 deletions(-) create mode 100644 invokeai/frontend/web/src/app/components/AuxiliaryProgressIndicator.tsx create mode 100644 invokeai/frontend/web/src/common/components/IAITextarea.tsx create mode 100644 invokeai/frontend/web/src/common/util/stopPastePropagation.ts diff --git a/invokeai/frontend/web/public/locales/en.json b/invokeai/frontend/web/public/locales/en.json index f82b3af677..319a920025 100644 --- a/invokeai/frontend/web/public/locales/en.json +++ b/invokeai/frontend/web/public/locales/en.json @@ -552,8 +552,8 @@ "canceled": "Processing Canceled", "tempFoldersEmptied": "Temp Folder Emptied", "uploadFailed": "Upload failed", - "uploadFailedMultipleImagesDesc": "Multiple images pasted, may only upload one image at a time", "uploadFailedUnableToLoadDesc": "Unable to load file", + "uploadFailedInvalidUploadDesc": "Must be single PNG or JPEG image", "downloadImageStarted": "Image Download Started", "imageCopied": "Image Copied", "imageLinkCopied": "Image Link Copied", diff --git a/invokeai/frontend/web/src/app/components/App.tsx b/invokeai/frontend/web/src/app/components/App.tsx index e819c04352..929c64edbb 100644 --- a/invokeai/frontend/web/src/app/components/App.tsx +++ b/invokeai/frontend/web/src/app/components/App.tsx @@ -22,6 +22,7 @@ import { languageSelector } from 'features/system/store/systemSelectors'; import i18n from 'i18n'; import Toaster from './Toaster'; import GlobalHotkeys from './GlobalHotkeys'; +import AuxiliaryProgressIndicator from './AuxiliaryProgressIndicator'; const DEFAULT_CONFIG = {}; @@ -99,6 +100,8 @@ const App = ({ + {/* */} + {!isApplicationReady && !loadingOverridden && ( { + const { isUploading } = system; + + let tooltip = ''; + + if (isUploading) { + tooltip = 'Uploading...'; + } + + return { + tooltip, + shouldShow: isUploading, + }; +}); + +export const AuxiliaryProgressIndicator = () => { + const { shouldShow, tooltip } = useAppSelector(selector); + + if (!shouldShow) { + return null; + } + + return ( + + + + + + ); +}; + +export default memo(AuxiliaryProgressIndicator); diff --git a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/imageUploaded.ts b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/imageUploaded.ts index c32da2e710..5b67be418f 100644 --- a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/imageUploaded.ts +++ b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/imageUploaded.ts @@ -3,6 +3,7 @@ import { startAppListening } from '..'; import { uploadAdded } from 'features/gallery/store/uploadsSlice'; import { imageSelected } from 'features/gallery/store/gallerySlice'; import { imageUploaded } from 'services/thunks/image'; +import { addToast } from 'features/system/store/systemSlice'; export const addImageUploadedListener = () => { startAppListening({ @@ -17,6 +18,8 @@ export const addImageUploadedListener = () => { dispatch(uploadAdded(image)); + dispatch(addToast({ title: 'Image Uploaded', status: 'success' })); + if (state.gallery.shouldAutoSwitchToNewImages) { dispatch(imageSelected(image)); } diff --git a/invokeai/frontend/web/src/common/components/IAIInput.tsx b/invokeai/frontend/web/src/common/components/IAIInput.tsx index 3e90dca83a..3cba36d2c9 100644 --- a/invokeai/frontend/web/src/common/components/IAIInput.tsx +++ b/invokeai/frontend/web/src/common/components/IAIInput.tsx @@ -5,6 +5,7 @@ import { Input, InputProps, } from '@chakra-ui/react'; +import { stopPastePropagation } from 'common/util/stopPastePropagation'; import { ChangeEvent, memo } from 'react'; interface IAIInputProps extends InputProps { @@ -31,7 +32,7 @@ const IAIInput = (props: IAIInputProps) => { {...formControlProps} > {label !== '' && {label}} - + ); }; diff --git a/invokeai/frontend/web/src/common/components/IAINumberInput.tsx b/invokeai/frontend/web/src/common/components/IAINumberInput.tsx index 762182eb47..bf598f3b12 100644 --- a/invokeai/frontend/web/src/common/components/IAINumberInput.tsx +++ b/invokeai/frontend/web/src/common/components/IAINumberInput.tsx @@ -14,6 +14,7 @@ import { Tooltip, TooltipProps, } from '@chakra-ui/react'; +import { stopPastePropagation } from 'common/util/stopPastePropagation'; import { clamp } from 'lodash-es'; import { FocusEvent, memo, useEffect, useState } from 'react'; @@ -125,6 +126,7 @@ const IAINumberInput = (props: Props) => { onChange={handleOnChange} onBlur={handleBlur} {...rest} + onPaste={stopPastePropagation} > {showStepper && ( diff --git a/invokeai/frontend/web/src/common/components/IAITextarea.tsx b/invokeai/frontend/web/src/common/components/IAITextarea.tsx new file mode 100644 index 0000000000..b5247887bb --- /dev/null +++ b/invokeai/frontend/web/src/common/components/IAITextarea.tsx @@ -0,0 +1,9 @@ +import { Textarea, TextareaProps, forwardRef } from '@chakra-ui/react'; +import { stopPastePropagation } from 'common/util/stopPastePropagation'; +import { memo } from 'react'; + +const IAITextarea = forwardRef((props: TextareaProps, ref) => { + return