diff --git a/apps/client/src/widgets/NoteDetail.tsx b/apps/client/src/widgets/NoteDetail.tsx index 10d40cee3..8a11c404d 100644 --- a/apps/client/src/widgets/NoteDetail.tsx +++ b/apps/client/src/widgets/NoteDetail.tsx @@ -18,7 +18,7 @@ import Image from "./type_widgets/Image"; import { ReadOnlyCode, EditableCode } from "./type_widgets/code/Code"; import Mermaid from "./type_widgets/Mermaid"; import MindMap from "./type_widgets/MindMap"; -import { AttachmentList } from "./type_widgets/Attachment"; +import { AttachmentDetail, AttachmentList } from "./type_widgets/Attachment"; /** * A `NoteType` altered by the note detail widget, taking into consideration whether the note is editable or not and adding special note types such as an empty one, @@ -100,6 +100,7 @@ function getCorrespondingWidget(noteType: ExtendedNoteType | undefined, props: T case "mermaid": return case "mindMap": return case "attachmentList": return + case "attachmentDetail": return default: break; } } diff --git a/apps/client/src/widgets/attachment_detail.ts b/apps/client/src/widgets/attachment_detail.ts index 9030245d8..29a2bf9ae 100644 --- a/apps/client/src/widgets/attachment_detail.ts +++ b/apps/client/src/widgets/attachment_detail.ts @@ -95,16 +95,4 @@ export default class AttachmentDetailWidget extends BasicWidget { throw new Error(t("attachment_detail_2.unrecognized_role", { role: this.attachment.role })); } } - - async entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) { - const attachmentRow = loadResults.getAttachmentRows().find((att) => att.attachmentId === this.attachment.attachmentId); - - if (attachmentRow) { - if (attachmentRow.isDeleted) { - this.toggleInt(false); - } else { - this.refresh(); - } - } - } } diff --git a/apps/client/src/widgets/type_widgets/Attachment.css b/apps/client/src/widgets/type_widgets/Attachment.css index 499f10508..bbc125a8c 100644 --- a/apps/client/src/widgets/type_widgets/Attachment.css +++ b/apps/client/src/widgets/type_widgets/Attachment.css @@ -13,7 +13,7 @@ } /* #endregion */ -/* #region Attachment detail */ +/* #region Attachment info */ .attachment-detail-widget { height: 100%; } @@ -82,4 +82,23 @@ .attachment-detail-wrapper.scheduled-for-deletion .attachment-content-wrapper img { filter: contrast(10%); } +/* #endregion */ + +/* #region Attachment detail */ +.attachment-detail { + padding-left: 15px; + padding-right: 15px; + height: 100%; + display: flex; + flex-direction: column; +} + +.attachment-detail .links-wrapper { + font-size: larger; + padding: 0 0 16px 0; +} + +.attachment-detail .attachment-wrapper { + flex-grow: 1; +} /* #endregion */ \ No newline at end of file diff --git a/apps/client/src/widgets/type_widgets/Attachment.tsx b/apps/client/src/widgets/type_widgets/Attachment.tsx index d685d7d8c..6864fd2b2 100644 --- a/apps/client/src/widgets/type_widgets/Attachment.tsx +++ b/apps/client/src/widgets/type_widgets/Attachment.tsx @@ -11,7 +11,11 @@ import Alert from "../react/Alert"; import utils from "../../services/utils"; import content_renderer from "../../services/content_renderer"; import { useTriliumEvent } from "../react/hooks"; +import froca from "../../services/froca"; +/** + * Displays the full list of attachments of a note and allows the user to interact with them. + */ export function AttachmentList({ note }: TypeWidgetProps) { const [ attachments, setAttachments ] = useState([]); @@ -33,7 +37,7 @@ export function AttachmentList({ note }: TypeWidgetProps) {
{attachments.length ? ( - attachments.map(attachment => ) + attachments.map(attachment => ) ) : ( {t("attachment_list.no_attachments")} @@ -69,7 +73,46 @@ function AttachmentListHeader({ noteId }: { noteId: string }) { ) } -function AttachmentDetail({ attachment, isFullDetail }: { attachment: FAttachment, isFullDetail?: boolean }) { +/** + * Displays information about a single attachment. + */ +export function AttachmentDetail({ note, viewScope }: TypeWidgetProps) { + const [ attachment, setAttachment ] = useState(undefined); + + useEffect(() => { + if (!viewScope?.attachmentId) return; + froca.getAttachment(viewScope.attachmentId).then(setAttachment); + }, [ viewScope ]); + + return ( +
+
+ {t("attachment_detail.owning_note")}{" "} + + {t("attachment_detail.you_can_also_open")}{" "} + + +
+ +
+ {attachment !== null ? ( + attachment && + ) : ( + {t("attachment_detail.attachment_deleted")} + )} +
+
+ ) +} + +function AttachmentInfo({ attachment, isFullDetail }: { attachment: FAttachment, isFullDetail?: boolean }) { const contentWrapper = useRef(null); useEffect(() => { diff --git a/apps/client/src/widgets/type_widgets_old/attachment_detail.ts b/apps/client/src/widgets/type_widgets_old/attachment_detail.ts deleted file mode 100644 index 9dbfa5210..000000000 --- a/apps/client/src/widgets/type_widgets_old/attachment_detail.ts +++ /dev/null @@ -1,101 +0,0 @@ -import TypeWidget from "./type_widget.js"; -import AttachmentDetailWidget from "../attachment_detail.js"; -import linkService from "../../services/link.js"; -import froca from "../../services/froca.js"; -import utils from "../../services/utils.js"; -import { t } from "../../services/i18n.js"; -import type FNote from "../../entities/fnote.js"; -import type { EventData } from "../../components/app_context.js"; - -const TPL = /*html*/` -
- - - - -
-
`; - -export default class AttachmentDetailTypeWidget extends TypeWidget { - $wrapper!: JQuery; - $linksWrapper!: JQuery; - - static getType() { - return "attachmentDetail"; - } - - doRender() { - this.$widget = $(TPL); - this.$wrapper = this.$widget.find(".attachment-wrapper"); - this.$linksWrapper = this.$widget.find(".links-wrapper"); - - super.doRender(); - } - - async doRefresh(note: Parameters[0]) { - this.$wrapper.empty(); - this.children = []; - - const $helpButton = $(` -