mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): make generation mode calculation more granular
This commit is contained in:
@ -1,9 +1,5 @@
|
||||
import { Box } from '@chakra-ui/react';
|
||||
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||
import { generationModeChanged } from 'features/canvas/store/canvasSlice';
|
||||
import { getCanvasData } from 'features/canvas/util/getCanvasData';
|
||||
import { getCanvasGenerationMode } from 'features/canvas/util/getCanvasGenerationMode';
|
||||
import { useDebounce } from 'react-use';
|
||||
import { useCanvasGenerationMode } from 'features/canvas/hooks/useCanvasGenerationMode';
|
||||
|
||||
const GENERATION_MODE_NAME_MAP = {
|
||||
txt2img: 'Text to Image',
|
||||
@ -12,38 +8,8 @@ const GENERATION_MODE_NAME_MAP = {
|
||||
outpaint: 'Inpaint',
|
||||
};
|
||||
|
||||
export const useGenerationMode = () => {
|
||||
const dispatch = useAppDispatch();
|
||||
const canvasState = useAppSelector((state) => state.canvas);
|
||||
|
||||
useDebounce(
|
||||
async () => {
|
||||
// Build canvas blobs
|
||||
const canvasBlobsAndImageData = await getCanvasData(canvasState);
|
||||
|
||||
if (!canvasBlobsAndImageData) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { baseImageData, maskImageData } = canvasBlobsAndImageData;
|
||||
|
||||
// Determine the generation mode
|
||||
const generationMode = getCanvasGenerationMode(
|
||||
baseImageData,
|
||||
maskImageData
|
||||
);
|
||||
|
||||
dispatch(generationModeChanged(generationMode));
|
||||
},
|
||||
1000,
|
||||
[dispatch, canvasState, generationModeChanged]
|
||||
);
|
||||
};
|
||||
|
||||
const GenerationModeStatusText = () => {
|
||||
const generationMode = useAppSelector((state) => state.canvas.generationMode);
|
||||
|
||||
useGenerationMode();
|
||||
const generationMode = useCanvasGenerationMode();
|
||||
|
||||
return (
|
||||
<Box>
|
||||
|
Reference in New Issue
Block a user