mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2025-01-08 11:57:36 +08:00
wip
This commit is contained in:
parent
5b3e1593ca
commit
922f8e3749
@ -1152,8 +1152,8 @@
|
||||
"reloadingIn": "Reloading in"
|
||||
},
|
||||
"toast": {
|
||||
"addedToBoard": "Added to board {{name}}'s assets",
|
||||
"addedToUncategorized": "Added to board $t(boards.uncategorized)'s assets",
|
||||
"addedToBoard": "Added to board {{name}}",
|
||||
"addedToUncategorized": "Added to board $t(boards.uncategorized)",
|
||||
"baseModelChanged": "Base Model Changed",
|
||||
"baseModelChangedCleared_one": "Cleared or disabled {{count}} incompatible submodel",
|
||||
"baseModelChangedCleared_other": "Cleared or disabled {{count}} incompatible submodels",
|
||||
|
@ -41,6 +41,11 @@ export const addImageUploadedFulfilledListener = (startAppListening: AppStartLis
|
||||
|
||||
log.debug({ imageDTO }, 'Image uploaded');
|
||||
|
||||
if (imageDTO.is_intermediate) {
|
||||
// No further action needed for intermediate images
|
||||
return;
|
||||
}
|
||||
|
||||
const boardId = imageDTO.board_id ?? 'none';
|
||||
|
||||
if (action.meta.arg.originalArgs.withToast) {
|
||||
@ -65,21 +70,23 @@ export const addImageUploadedFulfilledListener = (startAppListening: AppStartLis
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
/**
|
||||
* We only want to change the board and view if this is the first upload of a batch, else we end up hijacking
|
||||
* the user's gallery board and view selection:
|
||||
* - User uploads multiple images
|
||||
* - A couple uploads finish, but others are pending still
|
||||
* - User changes the board selection
|
||||
* - Pending uploads finish and change the board back to the original board
|
||||
* - User is confused as to why the board changed
|
||||
*
|
||||
* Default to true to not require _all_ image upload handlers to set this value
|
||||
*/
|
||||
const isFirstUploadOfBatch = action.meta.arg.originalArgs.isFirstUploadOfBatch ?? true;
|
||||
if (isFirstUploadOfBatch) {
|
||||
dispatch(boardIdSelected({ boardId }));
|
||||
dispatch(galleryViewChanged('assets'));
|
||||
if (action.meta.arg.originalArgs.switchToBoard) {
|
||||
/**
|
||||
* We only want to change the board and view if this is the first upload of a batch, else we end up hijacking
|
||||
* the user's gallery board and view selection:
|
||||
* - User uploads multiple images
|
||||
* - A couple uploads finish, but others are pending still
|
||||
* - User changes the board selection
|
||||
* - Pending uploads finish and change the board back to the original board
|
||||
* - User is confused as to why the board changed
|
||||
*
|
||||
* Default to true to not require _all_ image upload handlers to set this value
|
||||
*/
|
||||
const isFirstUploadOfBatch = action.meta.arg.originalArgs.isFirstUploadOfBatch ?? true;
|
||||
if (isFirstUploadOfBatch) {
|
||||
dispatch(galleryViewChanged('assets'));
|
||||
dispatch(boardIdSelected({ boardId, selectedImageName: imageDTO.image_name }));
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
@ -303,6 +303,7 @@ export class CanvasCompositorModule extends CanvasModuleBase {
|
||||
board_id: uploadOptions.is_intermediate ? undefined : selectAutoAddBoardId(this.manager.store.getState()),
|
||||
metadata: uploadOptions.metadata,
|
||||
withToast: false,
|
||||
switchToBoard: false,
|
||||
})
|
||||
);
|
||||
this.$isUploading.set(false);
|
||||
|
@ -494,6 +494,7 @@ export class CanvasEntityObjectRenderer extends CanvasModuleBase {
|
||||
image_category: 'other',
|
||||
is_intermediate: true,
|
||||
withToast: false,
|
||||
switchToBoard: false,
|
||||
});
|
||||
const imageObject = imageDTOToImageObject(imageDTO);
|
||||
if (replaceObjects) {
|
||||
|
@ -111,9 +111,13 @@ export const gallerySlice = createSlice({
|
||||
autoAssignBoardOnClickChanged: (state, action: PayloadAction<boolean>) => {
|
||||
state.autoAssignBoardOnClick = action.payload;
|
||||
},
|
||||
boardIdSelected: (state, action: PayloadAction<{ boardId: BoardId; selectedImageName?: string }>) => {
|
||||
state.selectedBoardId = action.payload.boardId;
|
||||
state.galleryView = 'images';
|
||||
boardIdSelected: (
|
||||
state,
|
||||
action: PayloadAction<{ boardId: BoardId; selectedImageName?: string; galleryView?: GalleryView }>
|
||||
) => {
|
||||
const { boardId, selectedImageName, galleryView } = action.payload;
|
||||
state.selectedBoardId = boardId;
|
||||
state.galleryView = galleryView ?? 'images';
|
||||
state.offset = 0;
|
||||
},
|
||||
autoAddBoardIdChanged: (state, action: PayloadAction<BoardId>) => {
|
||||
|
@ -272,6 +272,7 @@ export const imagesApi = api.injectEndpoints({
|
||||
metadata?: JsonObject;
|
||||
isFirstUploadOfBatch?: boolean;
|
||||
withToast?: boolean;
|
||||
switchToBoard?: boolean;
|
||||
}
|
||||
>({
|
||||
query: ({ file, image_category, is_intermediate, session_id, board_id, crop_visible, metadata }) => {
|
||||
@ -631,71 +632,35 @@ export type UploadImageArg = {
|
||||
crop_visible?: boolean;
|
||||
metadata?: JsonObject;
|
||||
withToast?: boolean;
|
||||
switchToBoard?: boolean;
|
||||
};
|
||||
const uploadArgDefaults: Partial<UploadImageArg> = {
|
||||
crop_visible: false,
|
||||
withToast: true,
|
||||
switchToBoard: true,
|
||||
};
|
||||
|
||||
export const uploadImage = (arg: UploadImageArg): Promise<ImageDTO> => {
|
||||
const {
|
||||
file,
|
||||
image_category,
|
||||
is_intermediate,
|
||||
crop_visible = false,
|
||||
board_id,
|
||||
metadata,
|
||||
session_id,
|
||||
withToast = true,
|
||||
} = arg;
|
||||
|
||||
const { dispatch } = getStore();
|
||||
|
||||
const req = dispatch(
|
||||
imagesApi.endpoints.uploadImage.initiate(
|
||||
{
|
||||
file,
|
||||
image_category,
|
||||
is_intermediate,
|
||||
crop_visible,
|
||||
board_id,
|
||||
metadata,
|
||||
session_id,
|
||||
withToast,
|
||||
},
|
||||
{ track: false }
|
||||
)
|
||||
);
|
||||
return req.unwrap();
|
||||
const req = dispatch(imagesApi.endpoints.uploadImage.initiate({ ...uploadArgDefaults, ...arg }, { track: false }));
|
||||
const imageDTO = req.unwrap();
|
||||
req.reset();
|
||||
return imageDTO;
|
||||
};
|
||||
|
||||
export const uploadImages = async (args: UploadImageArg[]): Promise<ImageDTO[]> => {
|
||||
const { dispatch } = getStore();
|
||||
const results = await Promise.allSettled(
|
||||
args.map((arg, i) => {
|
||||
const {
|
||||
file,
|
||||
image_category,
|
||||
is_intermediate,
|
||||
crop_visible = false,
|
||||
board_id,
|
||||
metadata,
|
||||
session_id,
|
||||
withToast = true,
|
||||
} = arg;
|
||||
const req = dispatch(
|
||||
imagesApi.endpoints.uploadImage.initiate(
|
||||
{
|
||||
file,
|
||||
image_category,
|
||||
is_intermediate,
|
||||
crop_visible,
|
||||
board_id,
|
||||
metadata,
|
||||
session_id,
|
||||
isFirstUploadOfBatch: i === 0,
|
||||
withToast,
|
||||
},
|
||||
{ ...uploadArgDefaults, ...arg, isFirstUploadOfBatch: i === 0 },
|
||||
{ track: false }
|
||||
)
|
||||
);
|
||||
return req.unwrap();
|
||||
const imageDTO = req.unwrap();
|
||||
req.reset();
|
||||
return imageDTO;
|
||||
})
|
||||
);
|
||||
return results.filter((r): r is PromiseFulfilledResult<ImageDTO> => r.status === 'fulfilled').map((r) => r.value);
|
||||
|
Loading…
Reference in New Issue
Block a user