diff --git a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/promptChanged.ts b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/promptChanged.ts index 513c087496..3a296b91c6 100644 --- a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/promptChanged.ts +++ b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/promptChanged.ts @@ -13,6 +13,7 @@ import { import { getShouldProcessPrompt } from 'features/dynamicPrompts/util/getShouldProcessPrompt'; import { getPresetModifiedPrompts } from 'features/nodes/util/graph/graphBuilderUtils'; import { activeStylePresetIdChanged } from 'features/stylePresets/store/stylePresetSlice'; +import { stylePresetsApi } from 'services/api/endpoints/stylePresets'; import { utilitiesApi } from 'services/api/endpoints/utilities'; import { socketConnected } from 'services/events/actions'; @@ -22,7 +23,10 @@ const matcher = isAnyOf( maxPromptsChanged, maxPromptsReset, socketConnected, - activeStylePresetIdChanged + activeStylePresetIdChanged, + stylePresetsApi.endpoints.deleteStylePreset.matchFulfilled, + stylePresetsApi.endpoints.updateStylePreset.matchFulfilled, + stylePresetsApi.endpoints.listStylePresets.matchFulfilled, ); export const addDynamicPromptsListener = (startAppListening: AppStartListening) => { diff --git a/invokeai/frontend/web/src/features/stylePresets/store/stylePresetSlice.ts b/invokeai/frontend/web/src/features/stylePresets/store/stylePresetSlice.ts index 45f770dd9b..d4d88e2023 100644 --- a/invokeai/frontend/web/src/features/stylePresets/store/stylePresetSlice.ts +++ b/invokeai/frontend/web/src/features/stylePresets/store/stylePresetSlice.ts @@ -1,6 +1,7 @@ import type { PayloadAction } from '@reduxjs/toolkit'; import { createSlice } from '@reduxjs/toolkit'; import type { PersistConfig } from 'app/store/store'; +import { stylePresetsApi } from 'services/api/endpoints/stylePresets'; import type { StylePresetState } from './types'; @@ -24,6 +25,26 @@ export const stylePresetSlice = createSlice({ state.viewMode = action.payload; }, }, + extraReducers(builder) { + builder.addMatcher(stylePresetsApi.endpoints.deleteStylePreset.matchFulfilled, (state, action) => { + if (state.activeStylePresetId === null) { + return; + } + const deletedId = action.meta.arg.originalArgs; + if (state.activeStylePresetId === deletedId) { + state.activeStylePresetId = null; + } + }); + builder.addMatcher(stylePresetsApi.endpoints.listStylePresets.matchFulfilled, (state, action) => { + if (state.activeStylePresetId === null) { + return; + } + const ids = action.payload.map((preset) => preset.id); + if (!ids.includes(state.activeStylePresetId)) { + state.activeStylePresetId = null; + } + }); + }, }); export const { activeStylePresetIdChanged, searchTermChanged, viewModeChanged } = stylePresetSlice.actions;