Skip to content

Commit

Permalink
feat(gui): add button to download image metadata JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Jul 2, 2023
1 parent a7be651 commit be39609
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions gui/src/components/card/ImageCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export function ImageCard(props: ImageCardProps) {
const { params, outputs, size } = image;

const [_hash, setHash] = useHash();
const [anchor, setAnchor] = useState<Maybe<HTMLElement>>();
const [blendAnchor, setBlendAnchor] = useState<Maybe<HTMLElement>>();
const [saveAnchor, setSaveAnchor] = useState<Maybe<HTMLElement>>();

const config = mustExist(useContext(ConfigContext));
const state = mustExist(useContext(StateContext));
Expand Down Expand Up @@ -91,8 +92,14 @@ export function ImageCard(props: ImageCardProps) {
window.open(outputs[index].url, '_blank');
}

function downloadMetadata() {
window.open(outputs[index].url + '.json', '_blank');
}

function close() {
setAnchor(undefined);
// TODO: split these up
setBlendAnchor(undefined);
setSaveAnchor(undefined);
}

const [index, setIndex] = useState(0);
Expand Down Expand Up @@ -151,10 +158,20 @@ export function ImageCard(props: ImageCardProps) {
</GridItem>
<GridItem xs={2}>
<Tooltip title={t('tooltip.save')}>
<IconButton onClick={downloadImage}>
<IconButton onClick={(event) => {
setSaveAnchor(event.currentTarget);
}}>
<Download />
</IconButton>
</Tooltip>
<Menu
anchorEl={saveAnchor}
open={doesExist(saveAnchor)}
onClose={close}
>
<MenuItem key='save-image' onClick={downloadImage}>{t('save.image')}</MenuItem>
<MenuItem key='save-metadata' onClick={downloadMetadata}>{t('save.metadata')}</MenuItem>
</Menu>
</GridItem>
<GridItem xs={2}>
<Tooltip title={t('tab.img2img')}>
Expand All @@ -180,14 +197,14 @@ export function ImageCard(props: ImageCardProps) {
<GridItem xs={2}>
<Tooltip title={t('tab.blend')}>
<IconButton onClick={(event) => {
setAnchor(event.currentTarget);
setBlendAnchor(event.currentTarget);
}}>
<Blender />
</IconButton>
</Tooltip>
<Menu
anchorEl={anchor}
open={doesExist(anchor)}
anchorEl={blendAnchor}
open={doesExist(blendAnchor)}
onClose={close}
>
{range(BLEND_SOURCES).map((idx) => <MenuItem key={idx} onClick={() => {
Expand Down

0 comments on commit be39609

Please sign in to comment.