fix(gui): handle cancel from file input
This commit is contained in:
parent
5a58a96a2a
commit
6b3c0fea45
|
@ -37,15 +37,17 @@ export function ImageInput(props: ImageInputProps) {
|
|||
accept={props.filter}
|
||||
type='file'
|
||||
onChange={(event) => {
|
||||
const files = mustExist(event.target.files);
|
||||
const file = mustExist(files[0]);
|
||||
const { files } = event.target;
|
||||
if (doesExist(files) && files.length > 0) {
|
||||
const file = mustExist(files[0]);
|
||||
|
||||
if (doesExist(image)) {
|
||||
URL.revokeObjectURL(image);
|
||||
if (doesExist(image)) {
|
||||
URL.revokeObjectURL(image);
|
||||
}
|
||||
|
||||
setImage(URL.createObjectURL(file));
|
||||
props.onChange(file);
|
||||
}
|
||||
|
||||
setImage(URL.createObjectURL(file));
|
||||
props.onChange(file);
|
||||
}}
|
||||
/>
|
||||
</Button>
|
||||
|
|
|
@ -84,12 +84,14 @@ export function Inpaint(props: InpaintProps) {
|
|||
|
||||
function drawSource(file: File) {
|
||||
const image = new Image();
|
||||
const src = URL.createObjectURL(file);
|
||||
image.onload = () => {
|
||||
const canvas = mustExist(canvasRef.current);
|
||||
const ctx = mustExist(canvas.getContext('2d'));
|
||||
ctx.drawImage(image, 0, 0);
|
||||
URL.revokeObjectURL(src);
|
||||
};
|
||||
image.src = URL.createObjectURL(file);
|
||||
image.src = src;
|
||||
}
|
||||
|
||||
function changeMask(file: File) {
|
||||
|
@ -153,8 +155,8 @@ export function Inpaint(props: InpaintProps) {
|
|||
staleTime: STALE_TIME,
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types, no-null/no-null
|
||||
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
||||
// eslint-disable-next-line no-null/no-null
|
||||
const canvasRef = useRef<HTMLCanvasElement>(null);
|
||||
const [clicks, setClicks] = useState<Array<Point>>([]);
|
||||
|
||||
const [painting, setPainting] = useState(false);
|
||||
|
|
Loading…
Reference in New Issue