Skip to content

Commit

Permalink
feat: optimize svg fileformat (#238)
Browse files Browse the repository at this point in the history
Signed-off-by: laixingyou <[email protected]>
  • Loading branch information
coder-sett authored Sep 25, 2023
1 parent 5ce7891 commit b554239
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
38 changes: 20 additions & 18 deletions apps/web/src/modules/analyze/components/DownCardLoadImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface DownLoadImageProps {
qrcodeLink?: string;
fileFormat: string;
onComplete: () => void;
onCompleteLoad: () => void;
}

const DownLoadImage = (props: DownLoadImageProps) => {
Expand All @@ -37,6 +38,7 @@ const DownLoadImage = (props: DownLoadImageProps) => {
loadingDownLoadImg,
fileFormat,
onComplete,
onCompleteLoad,
} = props;

const { t } = useTranslation();
Expand Down Expand Up @@ -70,6 +72,20 @@ const DownLoadImage = (props: DownLoadImageProps) => {
cardDownRef.current!.src = dataURL;
cardRef.current!.style.removeProperty('width');
await sleep(300);
onCompleteLoad();
};
const timer = setTimeout(() => {
fetchData().catch((e) => {
console.log('error:', e);
});
}, 300);
return () => {
clearTimeout(timer);
};
}, [downloadDivRef, cardRef, cardImgRef, size]);

useEffect(() => {
const downLoadImg = async () => {
if (loadingDownLoadImg) {
// download img
if (fileFormat === 'PNG') {
Expand Down Expand Up @@ -99,24 +115,10 @@ const DownLoadImage = (props: DownLoadImageProps) => {
}
}
};

const timer = setTimeout(() => {
fetchData().catch((e) => {
console.log('error:', e);
});
}, 300);
return () => {
clearTimeout(timer);
};
}, [
downloadDivRef,
cardRef,
cardImgRef,
onComplete,
size,
loadingDownLoadImg,
]);

downLoadImg().catch((e) => {
console.log('error:', e);
});
}, [loadingDownLoadImg]);
return (
<div
className={classnames(
Expand Down
30 changes: 18 additions & 12 deletions apps/web/src/modules/analyze/components/DownloadAndShare.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const DownloadAndShare = (props: {
const [open, setOpen] = useState(false);
const [fileFormat, setFileFormat] = useState('PNG');
const [loadingDownLoadImg, setLoadingDownLoadImg] = React.useState(false);
const [loadingPrviewImg, setLoadingPrviewImg] = React.useState(false);

return (
<>
Expand Down Expand Up @@ -172,24 +173,29 @@ const DownloadAndShare = (props: {
</label>
</div>
</RadioGroup.Root>
<div
onClick={() => {
setLoadingDownLoadImg(true);
}}
className="absolute right-10 top-24 flex h-7 w-20 cursor-pointer items-center justify-center rounded-sm border border-[#3A5BEF] text-xs text-[#3A5BEF]"
>
{loadingDownLoadImg ? (
<AiOutlineLoading className="t animate-spin" />
) : (
t('analyze:download')
)}
</div>
{loadingPrviewImg && (
<div
onClick={() => {
setLoadingDownLoadImg(true);
}}
className="absolute right-10 top-24 flex h-7 w-20 cursor-pointer items-center justify-center rounded-sm border border-[#3A5BEF] text-xs text-[#3A5BEF]"
>
{loadingDownLoadImg ? (
<AiOutlineLoading className="t animate-spin" />
) : (
t('analyze:download')
)}
</div>
)}
</div>
<DownCardLoadImage
size={downloadImageSize}
cardRef={cardRef}
loadingDownLoadImg={loadingDownLoadImg}
fileFormat={fileFormat}
onCompleteLoad={() => {
setLoadingPrviewImg(true);
}}
onComplete={() => {
setLoadingDownLoadImg(false);
}}
Expand Down

2 comments on commit b554239

@vercel
Copy link

@vercel vercel bot commented on b554239 Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on b554239 Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.