add boardToAddTo state so that result can be added to board when generation is complete

This commit is contained in:
Mary Hipp 2023-06-16 14:40:12 -04:00 committed by psychedelicious
parent 4defb92105
commit 7a2d3f628a
6 changed files with 23 additions and 6 deletions

View File

@ -9,6 +9,7 @@ import { imageMetadataReceived } from 'services/thunks/image';
import { sessionCanceled } from 'services/thunks/session';
import { isImageOutput } from 'services/types/guards';
import { progressImageSet } from 'features/system/store/systemSlice';
import { imageAddedToBoard } from '../../../../../../services/thunks/board';
const moduleLog = log.child({ namespace: 'socketio' });
const nodeDenylist = ['dataURL_image'];
@ -24,7 +25,8 @@ export const addInvocationCompleteEventListener = () => {
const sessionId = action.payload.data.graph_execution_state_id;
const { cancelType, isCancelScheduled } = getState().system;
const { cancelType, isCancelScheduled, boardIdToAddTo } =
getState().system;
// Handle scheduled cancelation
if (cancelType === 'scheduled' && isCancelScheduled) {
@ -38,6 +40,17 @@ export const addInvocationCompleteEventListener = () => {
if (isImageOutput(result) && !nodeDenylist.includes(node.type)) {
const { image_name } = result.image;
if (boardIdToAddTo) {
dispatch(
imageAddedToBoard({
requestBody: {
board_id: boardIdToAddTo,
image_name,
},
})
);
}
// Get its metadata
dispatch(
imageMetadataReceived({

View File

@ -25,7 +25,7 @@ type AdditionalBoardsState = {
limit: number;
total: number;
isLoading: boolean;
selectedBoardId: EntityId | null;
selectedBoardId?: string;
searchText?: string;
updateBoardModalOpen: boolean;
};
@ -36,7 +36,6 @@ export const initialBoardsState =
limit: 50,
total: 0,
isLoading: false,
selectedBoardId: null,
updateBoardModalOpen: false,
});
@ -55,7 +54,7 @@ const boardsSlice = createSlice({
boardRemoved: (state, action: PayloadAction<string>) => {
boardsAdapter.removeOne(state, action.payload);
},
boardIdSelected: (state, action: PayloadAction<string | null>) => {
boardIdSelected: (state, action: PayloadAction<string | undefined>) => {
state.selectedBoardId = action.payload;
},
setBoardSearchText: (state, action: PayloadAction<string>) => {

View File

@ -95,6 +95,7 @@ export interface SystemState {
shouldAntialiasProgressImage: boolean;
language: keyof typeof LANGUAGES;
isUploading: boolean;
boardIdToAddTo?: string;
}
export const initialSystemState: SystemState = {
@ -225,6 +226,7 @@ export const systemSlice = createSlice({
*/
builder.addCase(appSocketSubscribed, (state, action) => {
state.sessionId = action.payload.sessionId;
state.boardIdToAddTo = action.payload.boardId;
state.canceledSession = '';
});
@ -233,6 +235,7 @@ export const systemSlice = createSlice({
*/
builder.addCase(appSocketUnsubscribed, (state) => {
state.sessionId = null;
state.boardIdToAddTo = undefined;
});
/**

View File

@ -53,14 +53,14 @@ export const appSocketDisconnected = createAction<BaseSocketPayload>(
* Do not use. Only for use in middleware.
*/
export const socketSubscribed = createAction<
BaseSocketPayload & { sessionId: string }
BaseSocketPayload & { sessionId: string; boardId: string | undefined }
>('socket/socketSubscribed');
/**
* App-level Socket.IO Subscribed
*/
export const appSocketSubscribed = createAction<
BaseSocketPayload & { sessionId: string }
BaseSocketPayload & { sessionId: string; boardId: string | undefined }
>('socket/appSocketSubscribed');
/**

View File

@ -85,6 +85,7 @@ export const socketMiddleware = () => {
socketSubscribed({
sessionId: sessionId,
timestamp: getTimestamp(),
boardId: getState().boards.selectedBoardId,
})
);
}

View File

@ -44,6 +44,7 @@ export const setEventListeners = (arg: SetEventListenersArg) => {
socketSubscribed({
sessionId,
timestamp: getTimestamp(),
boardId: getState().boards.selectedBoardId,
})
);
}