diff --git a/invokeai/frontend/web/src/features/modelManagerV2/store/modelManagerV2Slice.ts b/invokeai/frontend/web/src/features/modelManagerV2/store/modelManagerV2Slice.ts index 80715cd7fb..39a009216a 100644 --- a/invokeai/frontend/web/src/features/modelManagerV2/store/modelManagerV2Slice.ts +++ b/invokeai/frontend/web/src/features/modelManagerV2/store/modelManagerV2Slice.ts @@ -8,6 +8,7 @@ type ModelManagerState = { selectedModelMode: 'edit' | 'view'; searchTerm: string; filteredModelType: string | null; + scanPath: string | undefined; }; const initialModelManagerState: ModelManagerState = { @@ -16,6 +17,7 @@ const initialModelManagerState: ModelManagerState = { selectedModelMode: 'view', filteredModelType: null, searchTerm: '', + scanPath: undefined, }; export const modelManagerV2Slice = createSlice({ @@ -36,10 +38,13 @@ export const modelManagerV2Slice = createSlice({ setFilteredModelType: (state, action: PayloadAction) => { state.filteredModelType = action.payload; }, + setScanPath: (state, action: PayloadAction) => { + state.scanPath = action.payload; + }, }, }); -export const { setSelectedModelKey, setSearchTerm, setFilteredModelType, setSelectedModelMode } = +export const { setSelectedModelKey, setSearchTerm, setFilteredModelType, setSelectedModelMode, setScanPath } = modelManagerV2Slice.actions; /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ diff --git a/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/ScanFolder/ScanFolderForm.tsx b/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/ScanFolder/ScanFolderForm.tsx index fe9b99ee81..cf8c4af50d 100644 --- a/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/ScanFolder/ScanFolderForm.tsx +++ b/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/ScanFolder/ScanFolderForm.tsx @@ -1,4 +1,6 @@ import { Button, Flex, FormControl, FormErrorMessage, FormLabel, Input } from '@invoke-ai/ui-library'; +import { useAppDispatch, useAppSelector } from 'app/store/storeHooks'; +import { setScanPath } from 'features/modelManagerV2/store/modelManagerV2Slice'; import type { ChangeEventHandler } from 'react'; import { useCallback, useState } from 'react'; import { useTranslation } from 'react-i18next'; @@ -7,7 +9,8 @@ import { useLazyScanFolderQuery } from 'services/api/endpoints/models'; import { ScanModelsResults } from './ScanFolderResults'; export const ScanModelsForm = () => { - const [scanPath, setScanPath] = useState(''); + const scanPath = useAppSelector((state) => state.modelmanagerV2.scanPath); + const dispatch = useAppDispatch(); const [errorMessage, setErrorMessage] = useState(''); const { t } = useTranslation(); @@ -21,10 +24,13 @@ export const ScanModelsForm = () => { }); }, [_scanFolder, scanPath]); - const handleSetScanPath: ChangeEventHandler = useCallback((e) => { - setScanPath(e.target.value); - setErrorMessage(''); - }, []); + const handleSetScanPath: ChangeEventHandler = useCallback( + (e) => { + dispatch(setScanPath(e.target.value)); + setErrorMessage(''); + }, + [dispatch] + ); return ( @@ -36,7 +42,11 @@ export const ScanModelsForm = () => { -