feat: add copy image in share menu

This commit is contained in:
Ryan Cao 2023-02-03 12:10:33 +08:00 committed by mauwii
parent 45a5ccba84
commit 70003ee5b1
No known key found for this signature in database
GPG Key ID: D923DB04ADB3F5AB
2 changed files with 25 additions and 0 deletions

View File

@ -48,6 +48,7 @@
"sendTo": "Send to",
"sendToImg2Img": "Send to Image to Image",
"sendToUnifiedCanvas": "Send To Unified Canvas",
"copyImage": "Copy Image",
"copyImageToLink": "Copy Image To Link",
"downloadImage": "Download Image",
"openInViewer": "Open In Viewer",

View File

@ -133,6 +133,22 @@ const CurrentImageButtons = () => {
dispatch(setActiveTab('img2img'));
};
const handleCopyImage = async () => {
if (!currentImage) return;
const blob = await fetch(currentImage.url).then((res) => res.blob());
const data = [new ClipboardItem({ [blob.type]: blob })];
await navigator.clipboard.write(data);
toast({
title: t('toast:imageCopied'),
status: 'success',
duration: 2500,
isClosable: true,
});
};
const handleCopyImageLink = () => {
navigator.clipboard
.writeText(
@ -412,6 +428,14 @@ const CurrentImageButtons = () => {
>
{t('parameters:sendToUnifiedCanvas')}
</IAIButton>
<IAIButton
size={'sm'}
onClick={handleCopyImage}
leftIcon={<FaCopy />}
>
{t('parameters:copyImage')}
</IAIButton>
<IAIButton
size={'sm'}
onClick={handleCopyImageLink}