diff --git a/web/src/components/ShareMemoDialog.tsx b/web/src/components/ShareMemoDialog.tsx index a5fc4f7c..ccff1733 100644 --- a/web/src/components/ShareMemoDialog.tsx +++ b/web/src/components/ShareMemoDialog.tsx @@ -49,11 +49,7 @@ const ShareMemoDialog: React.FC = (props: Props) => { pixelRatio: window.devicePixelRatio * 2, }) .then((url) => { - const a = document.createElement("a"); - a.href = url; - a.download = `memos-${getDateTimeString(Date.now())}.png`; - a.click(); - + downloadFileFromUrl(url, `memos-${getDateTimeString(Date.now())}.png`); downloadingImageState.setFinish(); }) .catch((err) => { @@ -61,6 +57,18 @@ const ShareMemoDialog: React.FC = (props: Props) => { }); }; + const handleDownloadTextFileBtnClick = () => { + const blob = new Blob([memo.content], { type: "text/plain;charset=utf-8" }); + downloadFileFromUrl(URL.createObjectURL(blob), `memos-${getDateTimeString(Date.now())}.md`); + }; + + const downloadFileFromUrl = (url: string, filename: string) => { + const a = document.createElement("a"); + a.href = url; + a.download = filename; + a.click(); + }; + const handleCopyLinkBtnClick = () => { copy(`${window.location.origin}/m/${memo.id}`); toast.success(t("message.succeed-copy-link")); @@ -88,6 +96,10 @@ const ShareMemoDialog: React.FC = (props: Props) => { )} {t("common.image")} +