feat: view all images of a memo (#393)

* feat: view all images of a memo

* fix: function arguments

* refactor: unified image preview

* refactor: image preview for resource dialog

Co-authored-by: XQ <qiaobingxue1998@163.com>
This commit is contained in:
Zhou Yunliang
2022-11-02 20:00:28 +08:00
committed by GitHub
parent bebcabc292
commit 91a61e058a
6 changed files with 47 additions and 125 deletions

View File

@ -161,9 +161,15 @@ const Memo: React.FC<Props> = (props: Props) => {
}
}
} else if (targetEl.tagName === "IMG") {
const imgUrl = targetEl.getAttribute("src");
if (imgUrl) {
showPreviewImageDialog(imgUrl);
const currImgUrl = targetEl.getAttribute("src");
if (currImgUrl) {
// use regex to get all image urls from memo content
const imageUrls = memo.content.match(/!\[.*?\]\((.*?)\)/g)?.map((item) => item.match(/\((.*?)\)/)?.[1] ?? "") ?? [];
showPreviewImageDialog(
imageUrls,
imageUrls.findIndex((item) => item === currImgUrl)
);
}
}
};