chore(ts): start port of widgets/buttons/attachment_actions

This commit is contained in:
Panagiotis Papadopoulos 2025-02-22 17:39:30 +01:00
parent 70756fe795
commit bf15192b25

View File

@ -8,6 +8,8 @@ import appContext from "../../components/app_context.js";
import openService from "../../services/open.js";
import utils from "../../services/utils.js";
import { Dropdown } from "bootstrap";
import type attachmentsApiRoute from "../../../../routes/api/attachments.js"
import type FAttachment from "../../entities/fattachment.js";
const TPL = `
<div class="dropdown attachment-actions">
@ -79,7 +81,12 @@ const TPL = `
</div>`;
export default class AttachmentActionsWidget extends BasicWidget {
constructor(attachment, isFullDetail) {
$uploadNewRevisionInput!: JQuery<HTMLInputElement>;
attachment: FAttachment;
isFullDetail: boolean;
dropdown!: Dropdown;
constructor(attachment: FAttachment, isFullDetail: boolean) {
super();
this.attachment = attachment;
@ -92,21 +99,22 @@ export default class AttachmentActionsWidget extends BasicWidget {
doRender() {
this.$widget = $(TPL);
this.dropdown = Dropdown.getOrCreateInstance(this.$widget.find("[data-bs-toggle='dropdown']"));
this.dropdown = Dropdown.getOrCreateInstance(this.$widget.find("[data-bs-toggle='dropdown']")[0]);
this.$widget.on("click", ".dropdown-item", () => this.dropdown.toggle());
this.$uploadNewRevisionInput = this.$widget.find(".attachment-upload-new-revision-input");
this.$uploadNewRevisionInput.on("change", async () => {
const fileToUpload = this.$uploadNewRevisionInput[0].files[0]; // copy to allow reset below
const fileToUpload = this.$uploadNewRevisionInput[0].files?.item(0); // copy to allow reset below
this.$uploadNewRevisionInput.val("");
if (fileToUpload) {
const result = await server.upload(`attachments/${this.attachmentId}/file`, fileToUpload);
if (result.uploaded) {
toastService.showMessage(t("attachments_actions.upload_success"));
} else {
toastService.showError(t("attachments_actions.upload_failed"));
}
}
});
const isElectron = utils.isElectron();
@ -122,6 +130,7 @@ export default class AttachmentActionsWidget extends BasicWidget {
const $openAttachmentCustomButton = this.$widget.find("[data-trigger-command='openAttachmentCustom']");
$openAttachmentCustomButton.addClass("disabled").append($('<span class="bx bx-info-circle disabled-tooltip" />').attr("title", t("attachments_actions.open_custom_client_only")));
}
}
async openAttachmentCommand() {
@ -141,7 +150,8 @@ export default class AttachmentActionsWidget extends BasicWidget {
}
async copyAttachmentLinkToClipboardCommand() {
this.parent.copyAttachmentLinkToClipboard();
//TriliumNextTODO: the parent here is AttachmentDetailWidget
this.parent?.copyAttachmentLinkToClipboard();
}
async deleteAttachmentCommand() {
@ -158,7 +168,8 @@ export default class AttachmentActionsWidget extends BasicWidget {
return;
}
const { note: newNote } = await server.post(`attachments/${this.attachmentId}/convert-to-note`);
const { note: newNote } = await server.post<ReturnType<typeof attachmentsApiRoute.convertAttachmentToNote>>(`attachments/${this.attachmentId}/convert-to-note`);
toastService.showMessage(t("attachments_actions.convert_success", { title: this.attachment.title }));
await ws.waitForMaxKnownEntityChangeId();
await appContext.tabManager.getActiveContext().setNote(newNote.noteId);