mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
chore(ui): clean up modelSlice
This commit is contained in:
parent
84b801d88f
commit
9f4d39aa42
@ -13,26 +13,15 @@ export const modelsAdapter = createEntityAdapter<Model>({
|
|||||||
sortComparer: (a, b) => a.name.localeCompare(b.name),
|
sortComparer: (a, b) => a.name.localeCompare(b.name),
|
||||||
});
|
});
|
||||||
|
|
||||||
type AdditionalModelsState = {
|
export const initialModelsState = modelsAdapter.getInitialState();
|
||||||
selectedModelName: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const initialModelsState =
|
|
||||||
modelsAdapter.getInitialState<AdditionalModelsState>({
|
|
||||||
selectedModelName: '',
|
|
||||||
});
|
|
||||||
|
|
||||||
export type ModelsState = typeof initialModelsState;
|
export type ModelsState = typeof initialModelsState;
|
||||||
|
|
||||||
export const modelsSlice = createSlice({
|
export const modelsSlice = createSlice({
|
||||||
name: 'models',
|
name: 'models',
|
||||||
initialState: modelsAdapter.getInitialState(),
|
initialState: initialModelsState,
|
||||||
// initialState: initialModelsState,
|
|
||||||
reducers: {
|
reducers: {
|
||||||
modelAdded: modelsAdapter.upsertOne,
|
modelAdded: modelsAdapter.upsertOne,
|
||||||
// modelSelected: (state, action: PayloadAction<string>) => {
|
|
||||||
// state.selectedModelName = action.payload;
|
|
||||||
// },
|
|
||||||
},
|
},
|
||||||
extraReducers(builder) {
|
extraReducers(builder) {
|
||||||
/**
|
/**
|
||||||
@ -41,32 +30,10 @@ export const modelsSlice = createSlice({
|
|||||||
builder.addCase(receivedModels.fulfilled, (state, action) => {
|
builder.addCase(receivedModels.fulfilled, (state, action) => {
|
||||||
const models = action.payload;
|
const models = action.payload;
|
||||||
modelsAdapter.setAll(state, models);
|
modelsAdapter.setAll(state, models);
|
||||||
|
|
||||||
// If the current selected model is `''` or isn't actually in the list of models,
|
|
||||||
// choose a random model
|
|
||||||
// if (
|
|
||||||
// !state.selectedModelName ||
|
|
||||||
// !keys(models).includes(state.selectedModelName)
|
|
||||||
// ) {
|
|
||||||
// const randomModel = sample(models);
|
|
||||||
|
|
||||||
// if (randomModel) {
|
|
||||||
// state.selectedModelName = randomModel.name;
|
|
||||||
// } else {
|
|
||||||
// state.selectedModelName = '';
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// export const selectedModelSelector = (state: RootState) => {
|
|
||||||
// const { selectedModelName } = state.models;
|
|
||||||
// const selectedModel = selectModelsById(state, selectedModelName);
|
|
||||||
|
|
||||||
// return selectedModel ?? null;
|
|
||||||
// };
|
|
||||||
|
|
||||||
export const {
|
export const {
|
||||||
selectAll: selectModelsAll,
|
selectAll: selectModelsAll,
|
||||||
selectById: selectModelsById,
|
selectById: selectModelsById,
|
||||||
@ -75,9 +42,6 @@ export const {
|
|||||||
selectTotal: selectModelsTotal,
|
selectTotal: selectModelsTotal,
|
||||||
} = modelsAdapter.getSelectors<RootState>((state) => state.models);
|
} = modelsAdapter.getSelectors<RootState>((state) => state.models);
|
||||||
|
|
||||||
export const {
|
export const { modelAdded } = modelsSlice.actions;
|
||||||
modelAdded,
|
|
||||||
// modelSelected
|
|
||||||
} = modelsSlice.actions;
|
|
||||||
|
|
||||||
export default modelsSlice.reducer;
|
export default modelsSlice.reducer;
|
||||||
|
Loading…
Reference in New Issue
Block a user