restore redux action for model changed so that model actually changes

This commit is contained in:
Mary Hipp 2024-03-07 13:43:39 -05:00
parent 4bbe6f3548
commit dc7154439d
5 changed files with 34 additions and 15 deletions

View File

@ -1,9 +1,9 @@
import { isAnyOf } from '@reduxjs/toolkit';
import type { AppStartListening } from 'app/store/middleware/listenerMiddleware';
import { controlAdapterModelChanged } from 'features/controlAdapters/store/actions';
import { CONTROLNET_MODEL_DEFAULT_PROCESSORS } from 'features/controlAdapters/store/constants';
import {
controlAdapterAutoConfigToggled,
controlAdapterModelChanged,
controlAdapterProcessortTypeChanged,
selectControlAdapterById,
} from 'features/controlAdapters/store/controlAdaptersSlice';

View File

@ -2,10 +2,11 @@ import type { AnyListenerPredicate } from '@reduxjs/toolkit';
import { logger } from 'app/logging/logger';
import type { AppStartListening } from 'app/store/middleware/listenerMiddleware';
import type { RootState } from 'app/store/store';
import { controlAdapterImageProcessed, controlAdapterModelChanged } from 'features/controlAdapters/store/actions';
import { controlAdapterImageProcessed } from 'features/controlAdapters/store/actions';
import {
controlAdapterAutoConfigToggled,
controlAdapterImageChanged,
controlAdapterModelChanged,
controlAdapterProcessorParamsChanged,
controlAdapterProcessortTypeChanged,
selectControlAdapterById,

View File

@ -5,10 +5,10 @@ import { useControlAdapterIsEnabled } from 'features/controlAdapters/hooks/useCo
import { useControlAdapterModel } from 'features/controlAdapters/hooks/useControlAdapterModel';
import { useControlAdapterModelQuery } from 'features/controlAdapters/hooks/useControlAdapterModelQuery';
import { useControlAdapterType } from 'features/controlAdapters/hooks/useControlAdapterType';
import { controlAdapterModelChanged } from 'features/controlAdapters/store/actions';
import { getModelKeyAndBase } from 'features/metadata/util/modelFetchingHelpers';
import { memo, useCallback, useMemo } from 'react';
import type { ControlNetModelConfig, IPAdapterModelConfig, T2IAdapterModelConfig } from 'services/api/types';
import { controlAdapterModelChanged } from '../../store/controlAdaptersSlice';
type ParamControlAdapterModelProps = {
id: string;
@ -25,7 +25,6 @@ const ParamControlAdapterModel = ({ id }: ParamControlAdapterModelProps) => {
const _onChange = useCallback(
(model: ControlNetModelConfig | IPAdapterModelConfig | T2IAdapterModelConfig | null) => {
console.log('on change');
if (!model) {
return;
}

View File

@ -1,15 +1,5 @@
import { createAction } from '@reduxjs/toolkit';
import type {
ParameterControlNetModel,
ParameterIPAdapterModel,
ParameterT2IAdapterModel,
} from 'features/parameters/types/parameterSchemas';
export const controlAdapterImageProcessed = createAction<{
id: string;
}>('controlAdapters/imageProcessed');
export const controlAdapterModelChanged = createAction<{
id: string;
model: ParameterControlNetModel | ParameterT2IAdapterModel | ParameterIPAdapterModel;
}>('controlAdapters/controlAdapterModelChanged');
}>('controlAdapters/imageProcessed');

View File

@ -21,6 +21,7 @@ import type {
T2IAdapterConfig,
} from './types';
import { isControlNet, isControlNetOrT2IAdapter, isIPAdapter, isT2IAdapter } from './types';
import { ParameterControlNetModel, ParameterT2IAdapterModel, ParameterIPAdapterModel } from '../../parameters/types/parameterSchemas';
const caAdapter = createEntityAdapter<ControlAdapterConfig, string>({
selectId: (ca) => ca.id,
@ -182,6 +183,33 @@ export const controlAdaptersSlice = createSlice({
changes: { model: null },
});
},
controlAdapterModelChanged: (
state,
action: PayloadAction<{
id: string;
model: ParameterControlNetModel | ParameterT2IAdapterModel | ParameterIPAdapterModel;
}>
) => {
const { id, model } = action.payload;
const cn = selectControlAdapterById(state, id);
if (!cn) {
return;
}
if (!isControlNetOrT2IAdapter(cn)) {
caAdapter.updateOne(state, { id, changes: { model } });
return;
}
const update: Update<ControlNetConfig | T2IAdapterConfig, string> = {
id,
changes: { model, shouldAutoConfig: true },
};
update.changes.processedControlImage = null;
caAdapter.updateOne(state, update);
},
controlAdapterWeightChanged: (state, action: PayloadAction<{ id: string; weight: number }>) => {
const { id, weight } = action.payload;
caAdapter.updateOne(state, { id, changes: { weight } });
@ -319,6 +347,7 @@ export const {
controlAdapterImageChanged,
controlAdapterProcessedImageChanged,
controlAdapterIsEnabledChanged,
controlAdapterModelChanged,
controlAdapterWeightChanged,
controlAdapterBeginStepPctChanged,
controlAdapterEndStepPctChanged,