feat(ui): use query to populate infill methods dropdown

- available infill methods is server state - remove it from client state, use the query to populate the dropdown
- add listener to ensure the selected infill method is an available one
This commit is contained in:
psychedelicious
2023-07-13 15:22:25 +10:00
parent 4d25d702a1
commit 978016ea51
5 changed files with 41 additions and 44 deletions

View File

@@ -1,25 +1,21 @@
import { createSelector } from '@reduxjs/toolkit';
import { stateSelector } from 'app/store/store';
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions';
import IAIMantineSelect from 'common/components/IAIMantineSelect';
import { generationSelector } from 'features/parameters/store/generationSelectors';
import { setInfillMethod } from 'features/parameters/store/generationSlice';
import { systemSelector } from 'features/system/store/systemSelectors';
import { memo, useCallback, useEffect, useMemo } from 'react';
import { memo, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { useGetAppConfigQuery } from '../../../../../../services/api/endpoints/appInfo';
import { setAvailableInfillMethods } from '../../../../../system/store/systemSlice';
import { useGetAppConfigQuery } from 'services/api/endpoints/appInfo';
const selector = createSelector(
[generationSelector, systemSelector],
(parameters, system) => {
const { infillMethod } = parameters;
const { infillMethods } = system;
[stateSelector],
({ generation }) => {
const { infillMethod } = generation;
return {
infillMethod,
infillMethods,
};
},
defaultSelectorOptions
@@ -27,9 +23,11 @@ const selector = createSelector(
const ParamInfillMethod = () => {
const dispatch = useAppDispatch();
const { infillMethod, infillMethods } = useAppSelector(selector);
const { infillMethod } = useAppSelector(selector);
const { data: appConfigData } = useGetAppConfigQuery();
const { data: appConfigData, isLoading } = useGetAppConfigQuery();
const infill_methods = appConfigData?.infill_methods;
const { t } = useTranslation();
@@ -40,24 +38,13 @@ const ParamInfillMethod = () => {
[dispatch]
);
useEffect(() => {
if (!appConfigData) return;
if (!appConfigData.patchmatch_enabled) {
const filteredMethods = infillMethods.filter(
(method) => method !== 'patchmatch'
);
dispatch(setAvailableInfillMethods(filteredMethods));
dispatch(setInfillMethod(filteredMethods[0]));
} else {
dispatch(setInfillMethod('patchmatch'));
}
}, [appConfigData, infillMethods, dispatch]);
return (
<IAIMantineSelect
disabled={infill_methods?.length === 0}
placeholder={isLoading ? 'Loading...' : undefined}
label={t('parameters.infillMethod')}
value={infillMethod}
data={infillMethods}
data={infill_methods ?? []}
onChange={handleChange}
/>
);

View File

@@ -4,8 +4,14 @@ 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 { LogLevelName } from 'roarr';
import { imageUploaded } from 'services/api/thunks/image';
import {
isAnySessionRejected,
sessionCanceled,
} from 'services/api/thunks/session';
import {
appSocketConnected,
appSocketDisconnected,
@@ -18,19 +24,11 @@ import {
appSocketUnsubscribed,
} from 'services/events/actions';
import { ProgressImage } from 'services/events/types';
import { imageUploaded } from 'services/api/thunks/image';
import {
isAnySessionRejected,
sessionCanceled,
} from 'services/api/thunks/session';
import { makeToast } from '../../../app/components/Toaster';
import { LANGUAGES } from '../components/LanguagePicker';
import { nodeTemplatesBuilt } from 'features/nodes/store/nodesSlice';
export type CancelStrategy = 'immediate' | 'scheduled';
export type InfillMethod = 'tile' | 'patchmatch';
export interface SystemState {
isGFPGANAvailable: boolean;
isESRGANAvailable: boolean;
@@ -87,10 +85,6 @@ export interface SystemState {
* When a session is canceled, its ID is stored here until a new session is created.
*/
canceledSession: string;
/**
* TODO: get this from backend
*/
infillMethods: InfillMethod[];
isPersisted: boolean;
shouldAntialiasProgressImage: boolean;
language: keyof typeof LANGUAGES;
@@ -128,7 +122,6 @@ export const initialSystemState: SystemState = {
shouldLogToConsole: true,
statusTranslationKey: 'common.statusDisconnected',
canceledSession: '',
infillMethods: ['tile', 'patchmatch'],
isPersisted: false,
language: 'en',
isUploading: false,
@@ -219,9 +212,6 @@ export const systemSlice = createSlice({
progressImageSet(state, action: PayloadAction<ProgressImage | null>) {
state.progressImage = action.payload;
},
setAvailableInfillMethods(state, action: PayloadAction<InfillMethod[]>) {
state.infillMethods = action.payload;
},
},
extraReducers(builder) {
/**
@@ -454,7 +444,6 @@ export const {
shouldAntialiasProgressImageChanged,
languageChanged,
progressImageSet,
setAvailableInfillMethods,
} = systemSlice.actions;
export default systemSlice.reducer;