Skip to content

Commit

Permalink
feat(context menu): ✨ condense top row of image context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
joshistoast authored and hipsterusername committed Oct 2, 2024
1 parent a8957aa commit 9b90834
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MenuItem } from '@invoke-ai/ui-library';
import { IconButton } from '@invoke-ai/ui-library';
import { useCopyImageToClipboard } from 'common/hooks/useCopyImageToClipboard';
import { useImageDTOContext } from 'features/gallery/contexts/ImageDTOContext';
import { memo, useCallback } from 'react';
Expand All @@ -19,9 +19,14 @@ export const ImageMenuItemCopy = memo(() => {
}

return (
<MenuItem icon={<PiCopyBold />} onClickCapture={onClick}>
{t('parameters.copyImage')}
</MenuItem>
<IconButton
icon={<PiCopyBold />}
aria-label={t('parameters.copyImage')}
tooltip={t('parameters.copyImage')}
onClickCapture={onClick}
variant="ghost"
colorScheme="base"
/>
);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MenuItem } from '@invoke-ai/ui-library';
import { IconButton } from '@invoke-ai/ui-library';
import { useAppDispatch } from 'app/store/storeHooks';
import { imagesToDeleteSelected } from 'features/deleteImageModal/store/slice';
import { useImageDTOContext } from 'features/gallery/contexts/ImageDTOContext';
Expand All @@ -16,9 +16,14 @@ export const ImageMenuItemDelete = memo(() => {
}, [dispatch, imageDTO]);

return (
<MenuItem isDestructive icon={<PiTrashSimpleBold />} onClickCapture={onClick}>
{t('gallery.deleteImage', { count: 1 })}
</MenuItem>
<IconButton
icon={<PiTrashSimpleBold />}
onClickCapture={onClick}
aria-label={t('gallery.deleteImage', { count: 1 })}
tooltip={t('gallery.deleteImage', { count: 1 })}
variant="ghost"
colorScheme="red"
/>
);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MenuItem } from '@invoke-ai/ui-library';
import { IconButton } from '@invoke-ai/ui-library';
import { useDownloadImage } from 'common/hooks/useDownloadImage';
import { useImageDTOContext } from 'features/gallery/contexts/ImageDTOContext';
import { memo, useCallback } from 'react';
Expand All @@ -15,9 +15,14 @@ export const ImageMenuItemDownload = memo(() => {
}, [downloadImage, imageDTO.image_name, imageDTO.image_url]);

return (
<MenuItem icon={<PiDownloadSimpleBold />} onClickCapture={onClick}>
{t('parameters.downloadImage')}
</MenuItem>
<IconButton
icon={<PiDownloadSimpleBold />}
aria-label={t('parameters.downloadImage')}
tooltip={t('parameters.downloadImage')}
variant="ghost"
colorScheme="base"
onClick={onClick}
/>
);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import { MenuItem } from '@invoke-ai/ui-library';
import { IconButton } from '@invoke-ai/ui-library';
import { useImageDTOContext } from 'features/gallery/contexts/ImageDTOContext';
import { memo } from 'react';
import { memo, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { PiArrowSquareOutBold } from 'react-icons/pi';

export const ImageMenuItemOpenInNewTab = memo(() => {
const { t } = useTranslation();
const imageDTO = useImageDTOContext();
const onClick = useCallback(() => {
window.open(imageDTO.image_url, '_blank');
}, [imageDTO.image_url]);

return (
<MenuItem as="a" href={imageDTO.image_url} target="_blank" icon={<PiArrowSquareOutBold />}>
{t('common.openInNewTab')}
</MenuItem>
<IconButton
onClickCapture={onClick}
aria-label={t('common.openInNewTab')}
tooltip={t('common.openInNewTab')}
icon={<PiArrowSquareOutBold />}
variant="ghost"
colorScheme="base"
/>
);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MenuItem } from '@invoke-ai/ui-library';
import { IconButton } from '@invoke-ai/ui-library';
import { useImageViewer } from 'features/gallery/components/ImageViewer/useImageViewer';
import { useImageDTOContext } from 'features/gallery/contexts/ImageDTOContext';
import { memo, useCallback } from 'react';
Expand All @@ -14,9 +14,14 @@ export const ImageMenuItemOpenInViewer = memo(() => {
}, [imageDTO, imageViewer]);

return (
<MenuItem icon={<PiArrowsOutBold />} onClick={onClick}>
{t('gallery.openInViewer')}
</MenuItem>
<IconButton
icon={<PiArrowsOutBold />}
onClick={onClick}
aria-label={t('common.openInViewer')}
tooltip={t('common.openInViewer')}
variant="ghost"
colorScheme="base"
/>
);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MenuItem } from '@invoke-ai/ui-library';
import { IconButton } from '@invoke-ai/ui-library';
import { createSelector } from '@reduxjs/toolkit';
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import { useImageDTOContext } from 'features/gallery/contexts/ImageDTOContext';
Expand All @@ -22,9 +22,15 @@ export const ImageMenuItemSelectForCompare = memo(() => {
}, [dispatch, imageDTO]);

return (
<MenuItem icon={<PiImagesBold />} isDisabled={!maySelectForCompare} onClick={onClick}>
{t('gallery.selectForCompare')}
</MenuItem>
<IconButton
icon={<PiImagesBold />}
isDisabled={!maySelectForCompare}
onClick={onClick}
aria-label={t('gallery.selectForCompare')}
tooltip={t('gallery.selectForCompare')}
variant="ghost"
colorScheme="base"
/>
);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MenuDivider } from '@invoke-ai/ui-library';
import { Flex, MenuDivider } from '@invoke-ai/ui-library';
import { ImageMenuItemChangeBoard } from 'features/gallery/components/ImageContextMenu/ImageMenuItemChangeBoard';
import { ImageMenuItemCopy } from 'features/gallery/components/ImageContextMenu/ImageMenuItemCopy';
import { ImageMenuItemDelete } from 'features/gallery/components/ImageContextMenu/ImageMenuItemDelete';
Expand All @@ -23,11 +23,14 @@ type SingleSelectionMenuItemsProps = {
const SingleSelectionMenuItems = ({ imageDTO }: SingleSelectionMenuItemsProps) => {
return (
<ImageDTOContextProvider value={imageDTO}>
<ImageMenuItemOpenInNewTab />
<ImageMenuItemCopy />
<ImageMenuItemDownload />
<ImageMenuItemOpenInViewer />
<ImageMenuItemSelectForCompare />
<Flex gap={2}>
<ImageMenuItemOpenInNewTab />
<ImageMenuItemCopy />
<ImageMenuItemDownload />
<ImageMenuItemOpenInViewer />
<ImageMenuItemSelectForCompare />
<ImageMenuItemDelete />
</Flex>
<MenuDivider />
<ImageMenuItemLoadWorkflow />
<ImageMenuItemMetadataRecallActions />
Expand All @@ -38,8 +41,6 @@ const SingleSelectionMenuItems = ({ imageDTO }: SingleSelectionMenuItemsProps) =
<MenuDivider />
<ImageMenuItemChangeBoard />
<ImageMenuItemStarUnstar />
<MenuDivider />
<ImageMenuItemDelete />
</ImageDTOContextProvider>
);
};
Expand Down

0 comments on commit 9b90834

Please sign in to comment.