Skip to content

Commit 8a2c78f

Browse files
fix(ui): dynamic prompts not recalculating when deleting or updating a style preset
The root cause was the active style preset not being reset when it was deleted, or no longer present in the list of style presets. - Add extra reducer to `stylePresetSlice` to reset the active preset if it is deleted or otherwise unavailable - Update the dynamic prompts listener to trigger on delete/update/list of style presets
1 parent bcc78bd commit 8a2c78f

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import { getShouldProcessPrompt } from 'features/dynamicPrompts/util/getShouldProcessPrompt';
1414
import { getPresetModifiedPrompts } from 'features/nodes/util/graph/graphBuilderUtils';
1515
import { activeStylePresetIdChanged } from 'features/stylePresets/store/stylePresetSlice';
16+
import { stylePresetsApi } from 'services/api/endpoints/stylePresets';
1617
import { utilitiesApi } from 'services/api/endpoints/utilities';
1718
import { socketConnected } from 'services/events/actions';
1819

@@ -22,7 +23,10 @@ const matcher = isAnyOf(
2223
maxPromptsChanged,
2324
maxPromptsReset,
2425
socketConnected,
25-
activeStylePresetIdChanged
26+
activeStylePresetIdChanged,
27+
stylePresetsApi.endpoints.deleteStylePreset.matchFulfilled,
28+
stylePresetsApi.endpoints.updateStylePreset.matchFulfilled,
29+
stylePresetsApi.endpoints.listStylePresets.matchFulfilled,
2630
);
2731

2832
export const addDynamicPromptsListener = (startAppListening: AppStartListening) => {

invokeai/frontend/web/src/features/stylePresets/store/stylePresetSlice.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { PayloadAction } from '@reduxjs/toolkit';
22
import { createSlice } from '@reduxjs/toolkit';
33
import type { PersistConfig } from 'app/store/store';
4+
import { stylePresetsApi } from 'services/api/endpoints/stylePresets';
45

56
import type { StylePresetState } from './types';
67

@@ -24,6 +25,26 @@ export const stylePresetSlice = createSlice({
2425
state.viewMode = action.payload;
2526
},
2627
},
28+
extraReducers(builder) {
29+
builder.addMatcher(stylePresetsApi.endpoints.deleteStylePreset.matchFulfilled, (state, action) => {
30+
if (state.activeStylePresetId === null) {
31+
return;
32+
}
33+
const deletedId = action.meta.arg.originalArgs;
34+
if (state.activeStylePresetId === deletedId) {
35+
state.activeStylePresetId = null;
36+
}
37+
});
38+
builder.addMatcher(stylePresetsApi.endpoints.listStylePresets.matchFulfilled, (state, action) => {
39+
if (state.activeStylePresetId === null) {
40+
return;
41+
}
42+
const ids = action.payload.map((preset) => preset.id);
43+
if (!ids.includes(state.activeStylePresetId)) {
44+
state.activeStylePresetId = null;
45+
}
46+
});
47+
},
2748
});
2849

2950
export const { activeStylePresetIdChanged, searchTermChanged, viewModeChanged } = stylePresetSlice.actions;

0 commit comments

Comments
 (0)