mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): display canvas generation mode in status text
- use the existing logic to determine if generation is txt2img, img2img, inpaint or outpaint - technically `outpaint` and `inpaint` are the same, just display "Inpaint" if its either - debounce this by 1s to prevent jank
This commit is contained in:
@ -0,0 +1,55 @@
|
||||
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';
|
||||
|
||||
const GENERATION_MODE_NAME_MAP = {
|
||||
txt2img: 'Text to Image',
|
||||
img2img: 'Image to Image',
|
||||
inpaint: 'Inpaint',
|
||||
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();
|
||||
|
||||
return (
|
||||
<Box>
|
||||
Mode: {generationMode ? GENERATION_MODE_NAME_MAP[generationMode] : '...'}
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
export default GenerationModeStatusText;
|
Reference in New Issue
Block a user