diff --git a/web/src/components/ShareMemoDialog.tsx b/web/src/components/ShareMemoDialog.tsx index ef2f3c98..55063c9e 100644 --- a/web/src/components/ShareMemoDialog.tsx +++ b/web/src/components/ShareMemoDialog.tsx @@ -24,7 +24,6 @@ interface Props extends DialogProps { interface State { memoAmount: number; memoVisibility: string; - generatedImgUrl: string; } const ShareMemoDialog: React.FC = (props: Props) => { @@ -38,8 +37,8 @@ const ShareMemoDialog: React.FC = (props: Props) => { const [state, setState] = useState({ memoAmount: 0, memoVisibility: propsMemo.visibility, - generatedImgUrl: "", }); + const createLoadingState = useLoading(false); const loadingState = useLoading(); const memoElRef = useRef(null); const memo = { @@ -64,39 +63,31 @@ const ShareMemoDialog: React.FC = (props: Props) => { }); }, []); - useEffect(() => { - if (loadingState.isLoading) { - return; - } - - if (!memoElRef.current) { - return; - } - toImage(memoElRef.current, { - pixelRatio: window.devicePixelRatio * 2, - }) - .then((url) => { - setState((state) => { - return { - ...state, - generatedImgUrl: url, - }; - }); - }) - .catch((err) => { - console.error(err); - }); - }, [loadingState.isLoading]); - const handleCloseBtnClick = () => { destroy(); }; const handleDownloadBtnClick = () => { - const a = document.createElement("a"); - a.href = state.generatedImgUrl; - a.download = `memos-${utils.getDateTimeString(Date.now())}.png`; - a.click(); + if (!memoElRef.current) { + return; + } + + createLoadingState.setLoading(); + + toImage(memoElRef.current, { + pixelRatio: window.devicePixelRatio * 2, + }) + .then((url) => { + const a = document.createElement("a"); + a.href = url; + a.download = `memos-${utils.getDateTimeString(Date.now())}.png`; + a.click(); + + createLoadingState.setFinish(); + }) + .catch((err) => { + console.error(err); + }); }; const handleCopyLinkBtnClick = () => { @@ -133,7 +124,6 @@ const ShareMemoDialog: React.FC = (props: Props) => {
- {state.generatedImgUrl !== "" && } {memo.createdAtStr}
@@ -176,8 +166,8 @@ const ShareMemoDialog: React.FC = (props: Props) => { ))}
-