mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
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
This commit is contained in:
parent
bcc78bde9b
commit
8a2c78f2e1
@ -13,6 +13,7 @@ import {
|
|||||||
import { getShouldProcessPrompt } from 'features/dynamicPrompts/util/getShouldProcessPrompt';
|
import { getShouldProcessPrompt } from 'features/dynamicPrompts/util/getShouldProcessPrompt';
|
||||||
import { getPresetModifiedPrompts } from 'features/nodes/util/graph/graphBuilderUtils';
|
import { getPresetModifiedPrompts } from 'features/nodes/util/graph/graphBuilderUtils';
|
||||||
import { activeStylePresetIdChanged } from 'features/stylePresets/store/stylePresetSlice';
|
import { activeStylePresetIdChanged } from 'features/stylePresets/store/stylePresetSlice';
|
||||||
|
import { stylePresetsApi } from 'services/api/endpoints/stylePresets';
|
||||||
import { utilitiesApi } from 'services/api/endpoints/utilities';
|
import { utilitiesApi } from 'services/api/endpoints/utilities';
|
||||||
import { socketConnected } from 'services/events/actions';
|
import { socketConnected } from 'services/events/actions';
|
||||||
|
|
||||||
@ -22,7 +23,10 @@ const matcher = isAnyOf(
|
|||||||
maxPromptsChanged,
|
maxPromptsChanged,
|
||||||
maxPromptsReset,
|
maxPromptsReset,
|
||||||
socketConnected,
|
socketConnected,
|
||||||
activeStylePresetIdChanged
|
activeStylePresetIdChanged,
|
||||||
|
stylePresetsApi.endpoints.deleteStylePreset.matchFulfilled,
|
||||||
|
stylePresetsApi.endpoints.updateStylePreset.matchFulfilled,
|
||||||
|
stylePresetsApi.endpoints.listStylePresets.matchFulfilled,
|
||||||
);
|
);
|
||||||
|
|
||||||
export const addDynamicPromptsListener = (startAppListening: AppStartListening) => {
|
export const addDynamicPromptsListener = (startAppListening: AppStartListening) => {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import type { PayloadAction } from '@reduxjs/toolkit';
|
import type { PayloadAction } from '@reduxjs/toolkit';
|
||||||
import { createSlice } from '@reduxjs/toolkit';
|
import { createSlice } from '@reduxjs/toolkit';
|
||||||
import type { PersistConfig } from 'app/store/store';
|
import type { PersistConfig } from 'app/store/store';
|
||||||
|
import { stylePresetsApi } from 'services/api/endpoints/stylePresets';
|
||||||
|
|
||||||
import type { StylePresetState } from './types';
|
import type { StylePresetState } from './types';
|
||||||
|
|
||||||
@ -24,6 +25,26 @@ export const stylePresetSlice = createSlice({
|
|||||||
state.viewMode = action.payload;
|
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;
|
export const { activeStylePresetIdChanged, searchTermChanged, viewModeChanged } = stylePresetSlice.actions;
|
||||||
|
Loading…
Reference in New Issue
Block a user