mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-24 04:00:59 +01:00
editor: enable attachment previews for files
This commit is contained in:
committed by
Abdullah Atta
parent
083e4e1150
commit
7227513783
@@ -61,10 +61,23 @@ export function DownloadAttachment(props: ToolProps) {
|
||||
/>
|
||||
);
|
||||
}
|
||||
const previewableFileExtensions = ["pdf"];
|
||||
|
||||
function canPreviewAttachment(attachment: Attachment) {
|
||||
if (!attachment) return false;
|
||||
const extension = attachment.filename?.split(".").pop();
|
||||
if (!extension) return false;
|
||||
|
||||
return previewableFileExtensions.indexOf(extension) > -1;
|
||||
}
|
||||
export function PreviewAttachment(props: ToolProps) {
|
||||
const { editor } = props;
|
||||
if (!editor.isActive("image")) return null;
|
||||
const attachmentNode =
|
||||
findSelectedNode(editor, "attachment") || findSelectedNode(editor, "image");
|
||||
const attachment = (attachmentNode?.attrs || {}) as Attachment;
|
||||
|
||||
if (!editor.isActive("image") && !canPreviewAttachment(attachment))
|
||||
return null;
|
||||
|
||||
return (
|
||||
<ToolButton
|
||||
|
||||
Reference in New Issue
Block a user