|
|
|
@ -4,28 +4,60 @@ import { userService } from "../services";
|
|
|
|
|
import toImage from "../labs/html2image";
|
|
|
|
|
import { ANIMATION_DURATION } from "../helpers/consts";
|
|
|
|
|
import * as utils from "../helpers/utils";
|
|
|
|
|
import { getMemoStats } from "../helpers/api";
|
|
|
|
|
import useLoading from "../hooks/useLoading";
|
|
|
|
|
import Icon from "./Icon";
|
|
|
|
|
import { generateDialog } from "./Dialog";
|
|
|
|
|
import MemoContent from "./MemoContent";
|
|
|
|
|
import "../less/share-memo-image-dialog.less";
|
|
|
|
|
import MemoResources from "./MemoResources";
|
|
|
|
|
import "../less/share-memo-image-dialog.less";
|
|
|
|
|
|
|
|
|
|
interface Props extends DialogProps {
|
|
|
|
|
memo: Memo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface State {
|
|
|
|
|
memoAmount: number;
|
|
|
|
|
shortcutImgUrl: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ShareMemoImageDialog: React.FC<Props> = (props: Props) => {
|
|
|
|
|
const { memo: propsMemo, destroy } = props;
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
const { user: userinfo } = userService.getState();
|
|
|
|
|
const [shortcutImgUrl, setShortcutImgUrl] = useState("");
|
|
|
|
|
const user = userService.getState().user as User;
|
|
|
|
|
const [state, setState] = useState<State>({
|
|
|
|
|
memoAmount: 0,
|
|
|
|
|
shortcutImgUrl: "",
|
|
|
|
|
});
|
|
|
|
|
const loadingState = useLoading();
|
|
|
|
|
const memoElRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
const memo = {
|
|
|
|
|
...propsMemo,
|
|
|
|
|
createdAtStr: utils.getDateTimeString(propsMemo.displayTs),
|
|
|
|
|
};
|
|
|
|
|
const memoElRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
const createdDays = Math.ceil((Date.now() - utils.getTimeStampByDate(user.createdTs)) / 1000 / 3600 / 24);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
getMemoStats(user.id)
|
|
|
|
|
.then(({ data: { data } }) => {
|
|
|
|
|
setState((state) => {
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
memoAmount: data.length,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
loadingState.setFinish();
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
console.error(error);
|
|
|
|
|
});
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (loadingState.isLoading) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
if (!memoElRef.current) {
|
|
|
|
|
return;
|
|
|
|
@ -36,13 +68,18 @@ const ShareMemoImageDialog: React.FC<Props> = (props: Props) => {
|
|
|
|
|
pixelRatio: window.devicePixelRatio * 2,
|
|
|
|
|
})
|
|
|
|
|
.then((url) => {
|
|
|
|
|
setShortcutImgUrl(url);
|
|
|
|
|
setState((state) => {
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
shortcutImgUrl: url,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
console.error(err);
|
|
|
|
|
});
|
|
|
|
|
}, ANIMATION_DURATION);
|
|
|
|
|
}, []);
|
|
|
|
|
}, [loadingState.isLoading]);
|
|
|
|
|
|
|
|
|
|
const handleCloseBtnClick = () => {
|
|
|
|
|
destroy();
|
|
|
|
@ -50,7 +87,7 @@ const ShareMemoImageDialog: React.FC<Props> = (props: Props) => {
|
|
|
|
|
|
|
|
|
|
const handleDownloadBtnClick = () => {
|
|
|
|
|
const a = document.createElement("a");
|
|
|
|
|
a.href = shortcutImgUrl;
|
|
|
|
|
a.href = state.shortcutImgUrl;
|
|
|
|
|
a.download = `memos-${utils.getDateTimeString(Date.now())}.png`;
|
|
|
|
|
a.click();
|
|
|
|
|
};
|
|
|
|
@ -67,20 +104,24 @@ const ShareMemoImageDialog: React.FC<Props> = (props: Props) => {
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="dialog-content-container">
|
|
|
|
|
<div className={`tip-words-container ${shortcutImgUrl ? "finish" : "loading"}`}>
|
|
|
|
|
<p className="tip-text">{shortcutImgUrl ? "Click to save the image 👇" : "Generating the screenshot..."}</p>
|
|
|
|
|
<div className={`tip-words-container ${state.shortcutImgUrl ? "finish" : "loading"}`}>
|
|
|
|
|
<p className="tip-text">{state.shortcutImgUrl ? "Click to save the image 👇" : "Generating the screenshot..."}</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="memo-container" ref={memoElRef}>
|
|
|
|
|
{shortcutImgUrl !== "" && <img className="memo-shortcut-img" onClick={handleDownloadBtnClick} src={shortcutImgUrl} />}
|
|
|
|
|
{state.shortcutImgUrl !== "" && <img className="memo-shortcut-img" onClick={handleDownloadBtnClick} src={state.shortcutImgUrl} />}
|
|
|
|
|
<span className="time-text">{memo.createdAtStr}</span>
|
|
|
|
|
<div className="memo-content-wrapper">
|
|
|
|
|
<MemoContent content={memo.content} displayConfig={{ enableExpand: false }} />
|
|
|
|
|
<MemoResources resourceList={memo.resourceList} />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="watermark-container">
|
|
|
|
|
<span className="normal-text">
|
|
|
|
|
<span className="icon-text">✍️</span> by <span className="name-text">{userinfo?.name}</span>
|
|
|
|
|
</span>
|
|
|
|
|
<div className="userinfo-container">
|
|
|
|
|
<span className="name-text">{user.name}</span>
|
|
|
|
|
<span className="usage-text">
|
|
|
|
|
{createdDays} DAYS / {state.memoAmount} MEMOS
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
<img className="logo-img" src="/logo.webp" alt="" />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|