Skip to content

Commit 75acece

Browse files
fix(ui): excessive toasts when generating on canvas
- Add `withToast` flag to `uploadImage` util - Skip the toast if this is not set - Use the flag to disable toasts when canvas does internal image-uploading stuff that should be invisible to user
1 parent a9db2ff commit 75acece

File tree

4 files changed

+48
-20
lines changed

4 files changed

+48
-20
lines changed

invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/imageUploaded.ts

+22-18
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,30 @@ export const addImageUploadedFulfilledListener = (startAppListening: AppStartLis
4141

4242
log.debug({ imageDTO }, 'Image uploaded');
4343

44-
const DEFAULT_UPLOADED_TOAST = {
45-
id: 'IMAGE_UPLOADED',
46-
title: t('toast.imageUploaded'),
47-
status: 'success',
48-
} as const;
49-
50-
// default action - just upload and alert user
5144
const boardId = imageDTO.board_id ?? 'none';
52-
if (lastUploadedToastTimeout !== null) {
53-
window.clearTimeout(lastUploadedToastTimeout);
45+
46+
if (action.meta.arg.originalArgs.withToast) {
47+
const DEFAULT_UPLOADED_TOAST = {
48+
id: 'IMAGE_UPLOADED',
49+
title: t('toast.imageUploaded'),
50+
status: 'success',
51+
} as const;
52+
53+
// default action - just upload and alert user
54+
if (lastUploadedToastTimeout !== null) {
55+
window.clearTimeout(lastUploadedToastTimeout);
56+
}
57+
const toastApi = toast({
58+
...DEFAULT_UPLOADED_TOAST,
59+
title: DEFAULT_UPLOADED_TOAST.title,
60+
description: getUploadedToastDescription(boardId, state),
61+
duration: null, // we will close the toast manually
62+
});
63+
lastUploadedToastTimeout = window.setTimeout(() => {
64+
toastApi.close();
65+
}, 3000);
5466
}
55-
const toastApi = toast({
56-
...DEFAULT_UPLOADED_TOAST,
57-
title: DEFAULT_UPLOADED_TOAST.title,
58-
description: getUploadedToastDescription(boardId, state),
59-
duration: null, // we will close the toast manually
60-
});
61-
lastUploadedToastTimeout = window.setTimeout(() => {
62-
toastApi.close();
63-
}, 3000);
67+
6468
/**
6569
* We only want to change the board and view if this is the first upload of a batch, else we end up hijacking
6670
* the user's gallery board and view selection:

invokeai/frontend/web/src/features/controlLayers/konva/CanvasCompositorModule.ts

+1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ export class CanvasCompositorModule extends CanvasModuleBase {
302302
is_intermediate: uploadOptions.is_intermediate,
303303
board_id: uploadOptions.is_intermediate ? undefined : selectAutoAddBoardId(this.manager.store.getState()),
304304
metadata: uploadOptions.metadata,
305+
withToast: false,
305306
})
306307
);
307308
this.$isUploading.set(false);

invokeai/frontend/web/src/features/controlLayers/konva/CanvasEntity/CanvasEntityObjectRenderer.ts

+1
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ export class CanvasEntityObjectRenderer extends CanvasModuleBase {
493493
file: new File([blob], `${this.id}_rasterized.png`, { type: 'image/png' }),
494494
image_category: 'other',
495495
is_intermediate: true,
496+
withToast: false,
496497
});
497498
const imageObject = imageDTOToImageObject(imageDTO);
498499
if (replaceObjects) {

invokeai/frontend/web/src/services/api/endpoints/images.ts

+24-2
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ export const imagesApi = api.injectEndpoints({
271271
crop_visible?: boolean;
272272
metadata?: JsonObject;
273273
isFirstUploadOfBatch?: boolean;
274+
withToast?: boolean;
274275
}
275276
>({
276277
query: ({ file, image_category, is_intermediate, session_id, board_id, crop_visible, metadata }) => {
@@ -629,10 +630,20 @@ export type UploadImageArg = {
629630
board_id?: string;
630631
crop_visible?: boolean;
631632
metadata?: JsonObject;
633+
withToast?: boolean;
632634
};
633635

634636
export const uploadImage = (arg: UploadImageArg): Promise<ImageDTO> => {
635-
const { file, image_category, is_intermediate, crop_visible = false, board_id, metadata, session_id } = arg;
637+
const {
638+
file,
639+
image_category,
640+
is_intermediate,
641+
crop_visible = false,
642+
board_id,
643+
metadata,
644+
session_id,
645+
withToast = true,
646+
} = arg;
636647

637648
const { dispatch } = getStore();
638649

@@ -646,6 +657,7 @@ export const uploadImage = (arg: UploadImageArg): Promise<ImageDTO> => {
646657
board_id,
647658
metadata,
648659
session_id,
660+
withToast,
649661
},
650662
{ track: false }
651663
)
@@ -657,7 +669,16 @@ export const uploadImages = async (args: UploadImageArg[]): Promise<ImageDTO[]>
657669
const { dispatch } = getStore();
658670
const results = await Promise.allSettled(
659671
args.map((arg, i) => {
660-
const { file, image_category, is_intermediate, crop_visible = false, board_id, metadata, session_id } = arg;
672+
const {
673+
file,
674+
image_category,
675+
is_intermediate,
676+
crop_visible = false,
677+
board_id,
678+
metadata,
679+
session_id,
680+
withToast = true,
681+
} = arg;
661682
const req = dispatch(
662683
imagesApi.endpoints.uploadImage.initiate(
663684
{
@@ -669,6 +690,7 @@ export const uploadImages = async (args: UploadImageArg[]): Promise<ImageDTO[]>
669690
metadata,
670691
session_id,
671692
isFirstUploadOfBatch: i === 0,
693+
withToast,
672694
},
673695
{ track: false }
674696
)

0 commit comments

Comments
 (0)