mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-04-23 03:00:31 -04:00
* initializing prompt expansion and putting response in prompt box working for all methods * properly disable UI and show loading state on prompt box when there is a pending prompt expansion item * misc wrapup: disable apploying prompt templates, dont block textarea resize handle * update progress to differentiate between prompt expansion and non * cleanup * lint * more cleanup * add image to background of loading state * add allowPromptExpansion for front-end gating * updated readiness text for needing to accept or discard * fix tsc * lint * lint * refactor(ui): prompt expansion logic * tidy(ui): remove unnecessary changes * revert(ui): unused arg on useImageUploadButton * feat(ui): simplify prompt expansion state * set pending for dragndrop and context menu * add readiness logic for generate tab * missing translation * update error handling for prompt expansion --------- Co-authored-by: Mary Hipp <maryhipp@Marys-Air.lan> Co-authored-by: Mary Hipp <maryhipp@Marys-MacBook-Air.local> Co-authored-by: psychedelicious <4822129+psychedelicious@users.noreply.github.com>
99 lines
1.7 KiB
TypeScript
99 lines
1.7 KiB
TypeScript
import { deepClone } from 'common/util/deepClone';
|
|
import { atom } from 'nanostores';
|
|
import type { ImageDTO } from 'services/api/types';
|
|
|
|
type SuccessState = {
|
|
isSuccess: true;
|
|
isError: false;
|
|
isPending: false;
|
|
result: string;
|
|
error: null;
|
|
imageDTO?: ImageDTO;
|
|
};
|
|
|
|
type ErrorState = {
|
|
isSuccess: false;
|
|
isError: true;
|
|
isPending: false;
|
|
result: null;
|
|
error: Error;
|
|
imageDTO?: ImageDTO;
|
|
};
|
|
|
|
type PendingState = {
|
|
isSuccess: false;
|
|
isError: false;
|
|
isPending: true;
|
|
result: null;
|
|
error: null;
|
|
imageDTO?: ImageDTO;
|
|
};
|
|
|
|
type IdleState = {
|
|
isSuccess: false;
|
|
isError: false;
|
|
isPending: false;
|
|
result: null;
|
|
error: null;
|
|
imageDTO?: ImageDTO;
|
|
};
|
|
|
|
export type PromptExpansionRequestState = IdleState | PendingState | SuccessState | ErrorState;
|
|
|
|
const IDLE_STATE: IdleState = {
|
|
isSuccess: false,
|
|
isError: false,
|
|
isPending: false,
|
|
result: null,
|
|
error: null,
|
|
imageDTO: undefined,
|
|
};
|
|
|
|
const $state = atom<PromptExpansionRequestState>(deepClone(IDLE_STATE));
|
|
|
|
const reset = () => {
|
|
$state.set(deepClone(IDLE_STATE));
|
|
};
|
|
|
|
const setPending = (imageDTO?: ImageDTO) => {
|
|
$state.set({
|
|
...$state.get(),
|
|
isSuccess: false,
|
|
isError: false,
|
|
isPending: true,
|
|
result: null,
|
|
error: null,
|
|
imageDTO,
|
|
});
|
|
};
|
|
|
|
const setSuccess = (result: string) => {
|
|
$state.set({
|
|
...$state.get(),
|
|
isSuccess: true,
|
|
isError: false,
|
|
isPending: false,
|
|
result,
|
|
error: null,
|
|
});
|
|
};
|
|
|
|
const setError = (error: Error) => {
|
|
$state.set({
|
|
...$state.get(),
|
|
isSuccess: false,
|
|
isError: true,
|
|
isPending: false,
|
|
result: null,
|
|
error,
|
|
});
|
|
};
|
|
|
|
export const promptExpansionApi = {
|
|
$state,
|
|
reset,
|
|
setPending,
|
|
setSuccess,
|
|
setError,
|
|
};
|