Skip to content

Commit

Permalink
add actions for copying image and opening image in new tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Mary Hipp authored and maryhipp committed Feb 25, 2025
1 parent 7bcbe18 commit b1c9f59
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { useAppDispatch } from 'app/store/storeHooks';
import { useClipboard } from 'common/hooks/useClipboard';
import { convertImageUrlToBlob } from 'common/util/convertImageUrlToBlob';
import { imageCopiedToClipboard } from 'features/gallery/store/actions';
import { toast } from 'features/toast/toast';
import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';

export const useCopyImageToClipboard = () => {
const { t } = useTranslation();
const clipboard = useClipboard();
const dispatch = useAppDispatch();

const copyImageToClipboard = useCallback(
async (image_url: string) => {
Expand All @@ -23,6 +26,7 @@ export const useCopyImageToClipboard = () => {
title: t('toast.imageCopied'),
status: 'success',
});
dispatch(imageCopiedToClipboard());
});
} catch (err) {
toast({
Expand All @@ -33,7 +37,7 @@ export const useCopyImageToClipboard = () => {
});
}
},
[clipboard, t]
[clipboard, t, dispatch]
);

return copyImageToClipboard;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { useAppDispatch } from 'app/store/storeHooks';
import { IconMenuItem } from 'common/components/IconMenuItem';
import { useImageDTOContext } from 'features/gallery/contexts/ImageDTOContext';
import { imageOpenedInNewTab } from 'features/gallery/store/actions';
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 dispatch = useAppDispatch();
const onClick = useCallback(() => {
window.open(imageDTO.image_url, '_blank');
}, [imageDTO.image_url]);
dispatch(imageOpenedInNewTab());
}, [imageDTO.image_url, dispatch]);

return (
<IconMenuItem
Expand Down
4 changes: 4 additions & 0 deletions invokeai/frontend/web/src/features/gallery/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ import { createAction } from '@reduxjs/toolkit';
export const sentImageToCanvas = createAction('gallery/sentImageToCanvas');

export const imageDownloaded = createAction('gallery/imageDownloaded');

export const imageCopiedToClipboard = createAction('gallery/imageCopiedToClipboard');

export const imageOpenedInNewTab = createAction('gallery/imageOpenedInNewTab');

0 comments on commit b1c9f59

Please sign in to comment.