diff --git a/apps/client/src/widgets/NoteDetail.tsx b/apps/client/src/widgets/NoteDetail.tsx index 44ed2ecd2..10d40cee3 100644 --- a/apps/client/src/widgets/NoteDetail.tsx +++ b/apps/client/src/widgets/NoteDetail.tsx @@ -18,6 +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"; /** * 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, @@ -98,6 +99,7 @@ function getCorrespondingWidget(noteType: ExtendedNoteType | undefined, props: T case "editableCode": return case "mermaid": return case "mindMap": return + case "attachmentList": return default: break; } } diff --git a/apps/client/src/widgets/react/HelpButton.tsx b/apps/client/src/widgets/react/HelpButton.tsx index 065252264..eb55b1c43 100644 --- a/apps/client/src/widgets/react/HelpButton.tsx +++ b/apps/client/src/widgets/react/HelpButton.tsx @@ -5,17 +5,18 @@ import { openInAppHelpFromUrl } from "../../services/utils"; interface HelpButtonProps { className?: string; helpPage: string; + title?: string; style?: CSSProperties; } -export default function HelpButton({ className, helpPage, style }: HelpButtonProps) { +export default function HelpButton({ className, helpPage, title, style }: HelpButtonProps) { return ( openInAppHelpFromUrl(helpPage)} - title={t("open-help-page")} + title={title ?? t("open-help-page")} style={style} /> ); -} \ No newline at end of file +} diff --git a/apps/client/src/widgets/type_widgets/Attachment.css b/apps/client/src/widgets/type_widgets/Attachment.css new file mode 100644 index 000000000..56a9b32e6 --- /dev/null +++ b/apps/client/src/widgets/type_widgets/Attachment.css @@ -0,0 +1,14 @@ +/* #region Attachment list */ +.attachment-list { + padding-left: 15px; + padding-right: 15px; +} + +.attachment-list .links-wrapper { + font-size: larger; + margin-bottom: 15px; + display: flex; + justify-content: space-between; + align-items: baseline; +} +/* #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 new file mode 100644 index 000000000..a2577e7ab --- /dev/null +++ b/apps/client/src/widgets/type_widgets/Attachment.tsx @@ -0,0 +1,41 @@ +import { t } from "i18next"; +import { TypeWidgetProps } from "./type_widget"; +import "./Attachment.css"; +import NoteLink from "../react/NoteLink"; +import Button from "../react/Button"; +import { useContext } from "preact/hooks"; +import { ParentComponent } from "../react/react_utils"; +import HelpButton from "../react/HelpButton"; + +export function AttachmentList({ note }: TypeWidgetProps) { + return ( + + + + ) +} + +function AttachmentListHeader({ noteId }: { noteId: string }) { + const parentComponent = useContext(ParentComponent); + + return ( + + + {t("attachment_list.owning_note")}{" "} + + + parentComponent?.triggerCommand("showUploadAttachmentsDialog", { noteId })} + /> + + + + + ) +} diff --git a/apps/client/src/widgets/type_widgets_old/attachment_list.ts b/apps/client/src/widgets/type_widgets_old/attachment_list.ts index aced1223c..8f1037631 100644 --- a/apps/client/src/widgets/type_widgets_old/attachment_list.ts +++ b/apps/client/src/widgets/type_widgets_old/attachment_list.ts @@ -6,26 +6,8 @@ import { t } from "../../services/i18n.js"; import type { EventData } from "../../components/app_context.js"; const TPL = /*html*/` - - - - - -`; +`; export default class AttachmentListTypeWidget extends TypeWidget { $list!: JQuery; @@ -48,7 +30,7 @@ export default class AttachmentListTypeWidget extends TypeWidget { const $helpButton = $(` + title="${}"> `); utils.initHelpButtons($helpButton); @@ -56,24 +38,6 @@ export default class AttachmentListTypeWidget extends TypeWidget { const noteLink = await linkService.createLink(this.noteId); // do separately to avoid race condition between empty() and .append() noteLink.addClass("use-tn-links"); - const $uploadButton = $(` - - - ${t("attachment_list.upload_attachments")} - - `); - - $uploadButton.on("click", () => { - if (this.noteId) { - this.triggerCommand("showUploadAttachmentsDialog", { noteId: this.noteId }); - } - }) - - this.$linksWrapper.empty().append( - $("").append(t("attachment_list.owning_note"), noteLink), - $(``).append($uploadButton, $helpButton) - ); - this.$list.empty(); this.children = []; this.renderedAttachmentIds = new Set();