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:
psychedelicious
2023-07-23 22:34:31 +10:00
parent 00d3cd4aed
commit 28031ead70
8 changed files with 81 additions and 18 deletions

View File

@ -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;