From 558c26d78ffc48c57a05e76138c476088ef6bac1 Mon Sep 17 00:00:00 2001 From: blessedcoolant <54517381+blessedcoolant@users.noreply.github.com> Date: Sat, 15 Jul 2023 22:22:22 +1200 Subject: [PATCH] feat: Create Model Manager Store --- invokeai/frontend/web/src/app/store/store.ts | 3 +++ .../src/features/system/store/systemSlice.ts | 22 +++--------------- .../ModelManager/store/modelManagerSlice.ts | 23 +++++++++++++++++++ .../store/modelmanagerSelectors.tsx | 3 +++ 4 files changed, 32 insertions(+), 19 deletions(-) create mode 100644 invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/store/modelManagerSlice.ts create mode 100644 invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/store/modelmanagerSelectors.tsx diff --git a/invokeai/frontend/web/src/app/store/store.ts b/invokeai/frontend/web/src/app/store/store.ts index 2bafd21a74..4725a2f921 100644 --- a/invokeai/frontend/web/src/app/store/store.ts +++ b/invokeai/frontend/web/src/app/store/store.ts @@ -21,6 +21,7 @@ import generationReducer from 'features/parameters/store/generationSlice'; import postprocessingReducer from 'features/parameters/store/postprocessingSlice'; import configReducer from 'features/system/store/configSlice'; import systemReducer from 'features/system/store/systemSlice'; +import modelmanagerReducer from 'features/ui/components/tabs/ModelManager/store/modelManagerSlice'; import hotkeysReducer from 'features/ui/store/hotkeysSlice'; import uiReducer from 'features/ui/store/uiSlice'; @@ -49,6 +50,7 @@ const allReducers = { dynamicPrompts: dynamicPromptsReducer, imageDeletion: imageDeletionReducer, lora: loraReducer, + modelmanager: modelmanagerReducer, [api.reducerPath]: api.reducer, }; @@ -67,6 +69,7 @@ const rememberedKeys: (keyof typeof allReducers)[] = [ 'controlNet', 'dynamicPrompts', 'lora', + 'modelmanager', ]; export const store = configureStore({ diff --git a/invokeai/frontend/web/src/features/system/store/systemSlice.ts b/invokeai/frontend/web/src/features/system/store/systemSlice.ts index 4d723378ba..875ae7a693 100644 --- a/invokeai/frontend/web/src/features/system/store/systemSlice.ts +++ b/invokeai/frontend/web/src/features/system/store/systemSlice.ts @@ -1,11 +1,10 @@ import { UseToastOptions } from '@chakra-ui/react'; import { PayloadAction, createSlice } from '@reduxjs/toolkit'; -import * as InvokeAI from 'app/types/invokeai'; import { InvokeLogLevel } from 'app/logging/useLogger'; import { userInvoked } from 'app/store/actions'; import { nodeTemplatesBuilt } from 'features/nodes/store/nodesSlice'; -import { TFuncKey, t } from 'i18next'; +import { t } from 'i18next'; import { LogLevelName } from 'roarr'; import { imageUploaded } from 'services/api/thunks/image'; import { @@ -44,8 +43,6 @@ export interface SystemState { isCancelable: boolean; enableImageDebugging: boolean; toastQueue: UseToastOptions[]; - searchFolder: string | null; - foundModels: InvokeAI.FoundModel[] | null; /** * The current progress image */ @@ -79,7 +76,7 @@ export interface SystemState { */ consoleLogLevel: InvokeLogLevel; shouldLogToConsole: boolean; - statusTranslationKey: TFuncKey; + statusTranslationKey: any; /** * When a session is canceled, its ID is stored here until a new session is created. */ @@ -106,8 +103,6 @@ export const initialSystemState: SystemState = { isCancelable: true, enableImageDebugging: false, toastQueue: [], - searchFolder: null, - foundModels: null, progressImage: null, shouldAntialiasProgressImage: false, sessionId: null, @@ -132,7 +127,7 @@ export const systemSlice = createSlice({ setIsProcessing: (state, action: PayloadAction) => { state.isProcessing = action.payload; }, - setCurrentStatus: (state, action: PayloadAction) => { + setCurrentStatus: (state, action: any) => { state.statusTranslationKey = action.payload; }, setShouldConfirmOnDelete: (state, action: PayloadAction) => { @@ -153,15 +148,6 @@ export const systemSlice = createSlice({ clearToastQueue: (state) => { state.toastQueue = []; }, - setSearchFolder: (state, action: PayloadAction) => { - state.searchFolder = action.payload; - }, - setFoundModels: ( - state, - action: PayloadAction - ) => { - state.foundModels = action.payload; - }, /** * A cancel was scheduled */ @@ -426,8 +412,6 @@ export const { setEnableImageDebugging, addToast, clearToastQueue, - setSearchFolder, - setFoundModels, cancelScheduled, scheduledCancelAborted, cancelTypeChanged, diff --git a/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/store/modelManagerSlice.ts b/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/store/modelManagerSlice.ts new file mode 100644 index 0000000000..c71407824e --- /dev/null +++ b/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/store/modelManagerSlice.ts @@ -0,0 +1,23 @@ +import { PayloadAction, createSlice } from '@reduxjs/toolkit'; + +type ModelManagerState = { + searchFolder: string | null; +}; + +const initialModelManagerState: ModelManagerState = { + searchFolder: null, +}; + +export const modelManagerSlice = createSlice({ + name: 'modelmanager', + initialState: initialModelManagerState, + reducers: { + setSearchFolder: (state, action: PayloadAction) => { + state.searchFolder = action.payload; + }, + }, +}); + +export const { setSearchFolder } = modelManagerSlice.actions; + +export default modelManagerSlice.reducer; diff --git a/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/store/modelmanagerSelectors.tsx b/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/store/modelmanagerSelectors.tsx new file mode 100644 index 0000000000..593282760a --- /dev/null +++ b/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/store/modelmanagerSelectors.tsx @@ -0,0 +1,3 @@ +import { RootState } from 'app/store/store'; + +export const modelmanagerSelector = (state: RootState) => state.modelmanager;