feat(ui): shift around init image recall logic

Retrieving the DTO happens as part of the metadata parsing, not recall. This way, we don't show the option to recall a nonexistent image.

This matches the flow for other metadata entities like models - we don't show the model recall button if the model isn't available.
This commit is contained in:
psychedelicious 2024-04-06 14:47:24 +11:00
parent adc30045a6
commit 55f7a7737a
3 changed files with 13 additions and 9 deletions

View File

@ -193,6 +193,7 @@ export const handlers = {
getLabel: () => t('metadata.initImage'),
parser: parsers.initialImage,
recaller: recallers.initialImage,
renderValue: async (imageDTO) => imageDTO.image_name,
}),
negativePrompt: buildHandlers({
getLabel: () => t('metadata.negativePrompt'),

View File

@ -1,3 +1,4 @@
import { getStore } from 'app/store/nanostores/store';
import {
initialControlNet,
initialIPAdapter,
@ -20,7 +21,6 @@ import type {
ParameterHeight,
ParameterHRFEnabled,
ParameterHRFMethod,
ParameterInitialImage,
ParameterModel,
ParameterNegativePrompt,
ParameterNegativeStylePromptSDXL,
@ -59,6 +59,8 @@ import {
isParameterWidth,
} from 'features/parameters/types/parameterSchemas';
import { get, isArray, isString } from 'lodash-es';
import { imagesApi } from 'services/api/endpoints/images';
import type { ImageDTO } from 'services/api/types';
import {
isControlNetModelConfig,
isIPAdapterModelConfig,
@ -137,8 +139,13 @@ const parseCFGRescaleMultiplier: MetadataParseFunc<ParameterCFGRescaleMultiplier
const parseScheduler: MetadataParseFunc<ParameterScheduler> = (metadata) =>
getProperty(metadata, 'scheduler', isParameterScheduler);
const parseInitialImage: MetadataParseFunc<ParameterInitialImage> = (metadata) =>
getProperty(metadata, 'init_image', isParameterInitialImage);
const parseInitialImage: MetadataParseFunc<ImageDTO> = async (metadata) => {
const imageName = await getProperty(metadata, 'init_image', isParameterInitialImage);
const imageDTORequest = getStore().dispatch(imagesApi.endpoints.getImageDTO.initiate(imageName));
const imageDTO = await imageDTORequest.unwrap();
imageDTORequest.unsubscribe();
return imageDTO;
};
const parseWidth: MetadataParseFunc<ParameterWidth> = (metadata) => getProperty(metadata, 'width', isParameterWidth);

View File

@ -35,7 +35,6 @@ import type {
ParameterHeight,
ParameterHRFEnabled,
ParameterHRFMethod,
ParameterInitialImage,
ParameterModel,
ParameterNegativePrompt,
ParameterNegativeStylePromptSDXL,
@ -63,7 +62,7 @@ import {
setRefinerStart,
setRefinerSteps,
} from 'features/sdxl/store/sdxlSlice';
import { imagesApi } from 'services/api/endpoints/images';
import type { ImageDTO } from 'services/api/types';
const recallPositivePrompt: MetadataRecallFunc<ParameterPositivePrompt> = (positivePrompt) => {
getStore().dispatch(setPositivePrompt(positivePrompt));
@ -97,10 +96,7 @@ const recallScheduler: MetadataRecallFunc<ParameterScheduler> = (scheduler) => {
getStore().dispatch(setScheduler(scheduler));
};
const recallInitialImage: MetadataRecallFunc<ParameterInitialImage> = async (initialImage) => {
const imageDTORequest = getStore().dispatch(imagesApi.endpoints.getImageDTO.initiate(initialImage));
const imageDTO = await imageDTORequest.unwrap();
imageDTORequest.unsubscribe();
const recallInitialImage: MetadataRecallFunc<ImageDTO> = async (imageDTO) => {
getStore().dispatch(initialImageChanged(imageDTO));
};