detect if user has patchmatch enabled

This commit is contained in:
Mary Hipp 2023-07-12 11:56:40 -04:00 committed by psychedelicious
parent fba25792f9
commit d6c914eedc
5 changed files with 2098 additions and 1589 deletions

View File

@ -6,8 +6,10 @@ import { generationSelector } from 'features/parameters/store/generationSelector
import { setInfillMethod } from 'features/parameters/store/generationSlice';
import { systemSelector } from 'features/system/store/systemSelectors';
import { memo, useCallback } from 'react';
import { memo, useCallback, useEffect, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { useGetAppConfigQuery } from '../../../../../../services/api/endpoints/appInfo';
import { setAvailableInfillMethods } from '../../../../../system/store/systemSlice';
const selector = createSelector(
[generationSelector, systemSelector],
@ -27,6 +29,8 @@ const ParamInfillMethod = () => {
const dispatch = useAppDispatch();
const { infillMethod, infillMethods } = useAppSelector(selector);
const { data: appConfigData } = useGetAppConfigQuery();
const { t } = useTranslation();
const handleChange = useCallback(
@ -36,6 +40,19 @@ 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
label={t('parameters.infillMethod')}

View File

@ -219,6 +219,9 @@ 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) {
/**
@ -451,6 +454,7 @@ export const {
shouldAntialiasProgressImageChanged,
languageChanged,
progressImageSet,
setAvailableInfillMethods,
} = systemSlice.actions;
export default systemSlice.reducer;

View File

@ -1,5 +1,5 @@
import { api } from '..';
import { AppVersion } from '../types';
import { AppVersion, AppConfig } from '../types';
export const appInfoApi = api.injectEndpoints({
endpoints: (build) => ({
@ -9,7 +9,13 @@ export const appInfoApi = api.injectEndpoints({
method: 'GET',
}),
}),
getAppConfig: build.query<AppConfig, void>({
query: () => ({
url: `app/config`,
method: 'GET',
}),
}),
}),
});
export const { useGetAppVersionQuery } = appInfoApi;
export const { useGetAppVersionQuery, useGetAppConfigQuery } = appInfoApi;

File diff suppressed because it is too large Load Diff

View File

@ -10,6 +10,7 @@ type TypeReq<T> = O.Required<T, 'type'>;
// App Info
export type AppVersion = components['schemas']['AppVersion'];
export type AppConfig = components['schemas']['AppConfig'];
// Images
export type ImageDTO = components['schemas']['ImageDTO'];