feat: export Memos as Markdown FIles (#2716)

This commit is contained in:
Noah Alderton 2024-01-07 19:40:50 -08:00 committed by GitHub
parent cafa7c5adc
commit 43e42079a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 5 deletions

View file

@ -49,11 +49,7 @@ const ShareMemoDialog: React.FC<Props> = (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: 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: Props) => {
)}
{t("common.image")}
</Button>
<Button color="neutral" variant="outlined" onClick={handleDownloadTextFileBtnClick}>
<Icon.File className="w-4 h-auto mr-1" />
{t("common.file")}
</Button>
<Button color="neutral" variant="outlined" onClick={handleCopyLinkBtnClick}>
<Icon.Link className="w-4 h-auto mr-1" />
{t("common.link")}

View file

@ -47,6 +47,7 @@
"fold": "Fold",
"expand": "Expand",
"image": "Image",
"file": "File",
"link": "Link",
"vacuum": "Vacuum",
"select": "Select",

View file

@ -1,6 +1,7 @@
{
"common": {
"about": "Acerca de",
"home": "Inicio",
"email": "Email",
"password": "Contraseña",
"username": "Usuario",
@ -37,6 +38,7 @@
"fold": "Plegar",
"expand": "Expandir",
"image": "Imagen",
"file": "Archivo",
"link": "Enlace",
"vacuum": "Vaciar",
"select": "Seleccionar",

View file

@ -40,6 +40,7 @@
"email": "Email",
"expand": "Agrandir",
"explore": "Explorer",
"file": "Fichier",
"filter": "Filtre",
"filter-period": "{{from}} à {{to}}",
"fold": "Rétracter",

View file

@ -37,6 +37,7 @@
"email": "Email",
"expand": "Espandi",
"explore": "Esplora",
"file": "File",
"filter": "Filtro",
"filter-period": "{{from}} a {{to}}",
"fold": "Riduci",