Skip to content

Commit

Permalink
fix(gui): only enable generate buttons after image sources exist (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Jan 21, 2023
1 parent e083411 commit 4898197
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
7 changes: 7 additions & 0 deletions gui/src/components/input/MaskCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export function MaskCanvas(props: MaskCanvasProps) {
const { canvas, ctx } = getClearContext(bufferRef);
ctx.globalAlpha = FULL_OPACITY;
ctx.drawImage(image, 0, 0, canvas.width, canvas.height);

URL.revokeObjectURL(src);

drawBuffer();
Expand Down Expand Up @@ -166,6 +167,12 @@ export function MaskCanvas(props: MaskCanvasProps) {
}

setBackground(URL.createObjectURL(source));

// initialize the mask if it does not exist
if (doesExist(mask) === false) {
getClearContext(bufferRef);
maskState.current = MASK_STATE.dirty;
}
}
}, [source]);

Expand Down
8 changes: 6 additions & 2 deletions gui/src/components/tab/Img2Img.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mustExist } from '@apextoaster/js-utils';
import { doesExist, mustExist } from '@apextoaster/js-utils';
import { Box, Button, Stack } from '@mui/material';
import * as React from 'react';
import { useMutation, useQueryClient } from 'react-query';
Expand Down Expand Up @@ -63,7 +63,11 @@ export function Img2Img() {
}}
/>
<UpscaleControl />
<Button variant='outlined' onClick={() => upload.mutate()}>Generate</Button>
<Button
disabled={doesExist(source) === false}
variant='outlined'
onClick={() => upload.mutate()}
>Generate</Button>
</Stack>
</Box>;
}
8 changes: 6 additions & 2 deletions gui/src/components/tab/Inpaint.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mustExist } from '@apextoaster/js-utils';
import { doesExist, mustExist } from '@apextoaster/js-utils';
import { Box, Button, Stack } from '@mui/material';
import * as React from 'react';
import { useMutation, useQuery, useQueryClient } from 'react-query';
Expand Down Expand Up @@ -161,7 +161,11 @@ export function Inpaint() {
</Stack>
<OutpaintControl />
<UpscaleControl />
<Button variant='outlined' onClick={() => upload.mutate()}>Generate</Button>
<Button
disabled={doesExist(source) === false || doesExist(mask) === false}
variant='outlined'
onClick={() => upload.mutate()}
>Generate</Button>
</Stack>
</Box>;
}
5 changes: 4 additions & 1 deletion gui/src/components/tab/Txt2Img.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ export function Txt2Img() {
/>
</Stack>
<UpscaleControl />
<Button variant='outlined' onClick={() => generate.mutate()}>Generate</Button>
<Button
variant='outlined'
onClick={() => generate.mutate()}
>Generate</Button>
</Stack>
</Box>;
}
10 changes: 6 additions & 4 deletions gui/src/components/tab/Upscale.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mustExist } from '@apextoaster/js-utils';
import { doesExist, mustExist } from '@apextoaster/js-utils';
import { Box, Button, Stack } from '@mui/material';
import * as React from 'react';
import { useMutation, useQueryClient } from 'react-query';
Expand All @@ -12,8 +12,6 @@ import { UpscaleControl } from '../control/UpscaleControl.js';
const { useContext } = React;

export function Upscale() {
const config = mustExist(useContext(ConfigContext));

async function uploadSource() {
const { model, upscale } = state.getState();

Expand Down Expand Up @@ -46,7 +44,11 @@ export function Upscale() {
});
}} />
<UpscaleControl />
<Button variant='outlined' onClick={() => upload.mutate()}>Generate</Button>
<Button
disabled={doesExist(params.source) === false}
variant='outlined'
onClick={() => upload.mutate()}
>Generate</Button>
</Stack>
</Box>;
}

0 comments on commit 4898197

Please sign in to comment.