mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
chore(ts): port of type_widgets/attachment_list
This commit is contained in:
parent
f6785f7980
commit
8f643c62e3
@ -3,6 +3,7 @@ import AttachmentDetailWidget from "../attachment_detail.js";
|
|||||||
import linkService from "../../services/link.js";
|
import linkService from "../../services/link.js";
|
||||||
import utils from "../../services/utils.js";
|
import utils from "../../services/utils.js";
|
||||||
import { t } from "../../services/i18n.js";
|
import { t } from "../../services/i18n.js";
|
||||||
|
import type { EventData } from "../../components/app_context.js";
|
||||||
|
|
||||||
const TPL = `
|
const TPL = `
|
||||||
<div class="attachment-list note-detail-printable">
|
<div class="attachment-list note-detail-printable">
|
||||||
@ -27,6 +28,10 @@ const TPL = `
|
|||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
export default class AttachmentListTypeWidget extends TypeWidget {
|
export default class AttachmentListTypeWidget extends TypeWidget {
|
||||||
|
$list!: JQuery<HTMLElement>;
|
||||||
|
$linksWrapper!: JQuery<HTMLElement>;
|
||||||
|
renderedAttachmentIds!: Set<string>;
|
||||||
|
|
||||||
static getType() {
|
static getType() {
|
||||||
return "attachmentList";
|
return "attachmentList";
|
||||||
}
|
}
|
||||||
@ -39,7 +44,10 @@ export default class AttachmentListTypeWidget extends TypeWidget {
|
|||||||
super.doRender();
|
super.doRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
async doRefresh(note) {
|
async doRefresh(note: Parameters<TypeWidget["doRefresh"]>[0]) {
|
||||||
|
// TriliumNextTODO: do we need to handle an undefined/null note?
|
||||||
|
if (!note) return false;
|
||||||
|
|
||||||
const $helpButton = $(`
|
const $helpButton = $(`
|
||||||
<button class="attachment-help-button icon-action bx bx-help-circle"
|
<button class="attachment-help-button icon-action bx bx-help-circle"
|
||||||
type="button" data-help-page="attachments.html"
|
type="button" data-help-page="attachments.html"
|
||||||
@ -56,7 +64,11 @@ export default class AttachmentListTypeWidget extends TypeWidget {
|
|||||||
$(`<div class="attachment-actions-toolbar">`).append(
|
$(`<div class="attachment-actions-toolbar">`).append(
|
||||||
$('<button class="btn btn-sm">')
|
$('<button class="btn btn-sm">')
|
||||||
.text(t("attachment_list.upload_attachments"))
|
.text(t("attachment_list.upload_attachments"))
|
||||||
.on("click", () => this.triggerCommand("showUploadAttachmentsDialog", { noteId: this.noteId })),
|
.on("click", () => {
|
||||||
|
if (this.noteId) {
|
||||||
|
this.triggerCommand("showUploadAttachmentsDialog", { noteId: this.noteId })
|
||||||
|
}
|
||||||
|
}),
|
||||||
$helpButton
|
$helpButton
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -83,9 +95,9 @@ export default class AttachmentListTypeWidget extends TypeWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async entitiesReloadedEvent({ loadResults }) {
|
async entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
|
||||||
// updates and deletions are handled by the detail, for new attachments the whole list has to be refreshed
|
// updates and deletions are handled by the detail, for new attachments the whole list has to be refreshed
|
||||||
const attachmentsAdded = loadResults.getAttachmentRows().some((att) => !this.renderedAttachmentIds.has(att.attachmentId));
|
const attachmentsAdded = loadResults.getAttachmentRows().some((att) => att.attachmentId && !this.renderedAttachmentIds.has(att.attachmentId));
|
||||||
|
|
||||||
if (attachmentsAdded) {
|
if (attachmentsAdded) {
|
||||||
this.refresh();
|
this.refresh();
|
Loading…
x
Reference in New Issue
Block a user