fix(ui): fix copying image link

This commit is contained in:
psychedelicious 2023-05-09 18:52:09 +10:00
parent 7bfb5640ad
commit fcf9c63049
2 changed files with 25 additions and 5 deletions

View File

@ -553,6 +553,7 @@
"downloadImageStarted": "Image Download Started",
"imageCopied": "Image Copied",
"imageLinkCopied": "Image Link Copied",
"problemCopyingImageLink": "Unable to Copy Image Link",
"imageNotLoaded": "No Image Loaded",
"imageNotLoadedDesc": "Could not find image",
"imageSavedToGallery": "Image Saved to Gallery",

View File

@ -184,13 +184,32 @@ const CurrentImageButtons = (props: CurrentImageButtonsProps) => {
// }, [getUrl, t, image?.url, toast]);
const handleCopyImageLink = useCallback(() => {
const url = image
? shouldTransformUrls
? getUrl(image.url)
: window.location.toString() + image.url
: '';
const getImageUrl = () => {
if (!image) {
return;
}
if (shouldTransformUrls) {
return getUrl(image.url);
}
if (image.url.startsWith('http')) {
return image.url;
}
return window.location.toString() + image.url;
};
const url = getImageUrl();
if (!url) {
toast({
title: t('toast.problemCopyingImageLink'),
status: 'error',
duration: 2500,
isClosable: true,
});
return;
}