From 0e843823d11a17871cd8e06c8aa6f833c9b94b22 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Thu, 26 Jun 2025 18:15:49 +1000 Subject: [PATCH] fix(ui): ensure image selected on first load --- .../listenerMiddleware/listeners/appStarted.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/appStarted.ts b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/appStarted.ts index 60a5310fcd..1bc9e297af 100644 --- a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/appStarted.ts +++ b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/appStarted.ts @@ -1,15 +1,29 @@ import { createAction } from '@reduxjs/toolkit'; import type { AppStartListening } from 'app/store/middleware/listenerMiddleware'; +import { selectLastSelectedImage } from 'features/gallery/store/gallerySelectors'; +import { imageSelected } from 'features/gallery/store/gallerySlice'; +import { imagesApi } from 'services/api/endpoints/images'; export const appStarted = createAction('app/appStarted'); export const addAppStartedListener = (startAppListening: AppStartListening) => { startAppListening({ actionCreator: appStarted, - effect: (action, { unsubscribe, cancelActiveListeners }) => { + effect: async (action, { unsubscribe, cancelActiveListeners, take, getState, dispatch }) => { // this should only run once cancelActiveListeners(); unsubscribe(); + + // ensure an image is selected when we load the first board + const firstImageLoad = await take(imagesApi.endpoints.getImageNames.matchFulfilled); + if (firstImageLoad !== null) { + const [{ payload }] = firstImageLoad; + const selectedImage = selectLastSelectedImage(getState()); + if (selectedImage) { + return; + } + dispatch(imageSelected(payload.image_names.at(0) ?? null)); + } }, }); };