diff --git a/apps/client/src/widgets/attachment_detail.ts b/apps/client/src/widgets/attachment_detail.ts deleted file mode 100644 index 7f15c9fa6..000000000 --- a/apps/client/src/widgets/attachment_detail.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { t } from "../services/i18n.js"; -import utils from "../services/utils.js"; -import AttachmentActionsWidget from "./buttons/attachments_actions.js"; -import BasicWidget from "./basic_widget.js"; -import options from "../services/options.js"; -import imageService from "../services/image.js"; -import linkService from "../services/link.js"; -import contentRenderer from "../services/content_renderer.js"; -import toastService from "../services/toast.js"; -import type FAttachment from "../entities/fattachment.js"; -import type { EventData } from "../components/app_context.js"; - -const TPL = /*html*/` -
- - -`; - -export default class AttachmentDetailWidget extends BasicWidget { - attachment: FAttachment; - attachmentActionsWidget: AttachmentActionsWidget; - isFullDetail: boolean; - $wrapper!: JQuery; - - constructor(attachment: FAttachment, isFullDetail: boolean) { - super(); - - this.contentSized(); - this.attachment = attachment; - this.attachmentActionsWidget = new AttachmentActionsWidget(attachment, isFullDetail); - this.isFullDetail = isFullDetail; - this.child(this.attachmentActionsWidget); - } - - doRender() { - this.$widget = $(TPL); - this.refresh(); - - super.doRender(); - } - - async refresh() { - this.$widget.find(".attachment-detail-wrapper").empty().append($(TPL).find(".attachment-detail-wrapper").html()); - this.$wrapper = this.$widget.find(".attachment-detail-wrapper"); - this.$wrapper.addClass(this.isFullDetail ? "full-detail" : "list-view"); - - const $deletionWarning = this.$wrapper.find(".attachment-deletion-warning"); - const { utcDateScheduledForErasureSince } = this.attachment; - - if (utcDateScheduledForErasureSince) { - this.$wrapper.addClass("scheduled-for-deletion"); - - const scheduledSinceTimestamp = utils.parseDate(utcDateScheduledForErasureSince)?.getTime(); - // use default value (30 days in seconds) from options_init as fallback, in case getInt returns null - const intervalMs = options.getInt("eraseUnusedAttachmentsAfterSeconds") || 2592000 * 1000; - const deletionTimestamp = scheduledSinceTimestamp + intervalMs; - const willBeDeletedInMs = deletionTimestamp - Date.now(); - - $deletionWarning.show(); - - if (willBeDeletedInMs >= 60000) { - $deletionWarning.text(t("attachment_detail_2.will_be_deleted_in", { time: utils.formatTimeInterval(willBeDeletedInMs) })); - } else { - $deletionWarning.text(t("attachment_detail_2.will_be_deleted_soon")); - } - - $deletionWarning.append(t("attachment_detail_2.deletion_reason")); - } else { - this.$wrapper.removeClass("scheduled-for-deletion"); - $deletionWarning.hide(); - } - - this.$wrapper.find(".attachment-actions-container").append(this.attachmentActionsWidget.render()); - - const { $renderedContent } = await ); - this.$wrapper.find(".attachment-content-wrapper").append($renderedContent); - } - -} diff --git a/apps/client/src/widgets/type_widgets/Attachment.css b/apps/client/src/widgets/type_widgets/Attachment.css index 9c5c502d7..4c5a58d7b 100644 --- a/apps/client/src/widgets/type_widgets/Attachment.css +++ b/apps/client/src/widgets/type_widgets/Attachment.css @@ -82,6 +82,10 @@ .attachment-detail-wrapper.scheduled-for-deletion .attachment-content-wrapper img { filter: contrast(10%); } + +.attachment-detail-wrapper .attachment-deletion-warning { + margin-top: 15px; +} /* #endregion */ /* #region Attachment detail */ diff --git a/apps/client/src/widgets/type_widgets/Attachment.tsx b/apps/client/src/widgets/type_widgets/Attachment.tsx index f5b0fd7a3..886b8e892 100644 --- a/apps/client/src/widgets/type_widgets/Attachment.tsx +++ b/apps/client/src/widgets/type_widgets/Attachment.tsx @@ -25,6 +25,7 @@ import dialog from "../../services/dialog"; import ws from "../../services/ws"; import appContext from "../../components/app_context"; import { ConvertAttachmentToNoteResponse } from "@triliumnext/commons"; +import options from "../../services/options"; /** * Displays the full list of attachments of a note and allows the user to interact with them. @@ -158,7 +159,7 @@ function AttachmentInfo({ attachment, isFullDetail }: { attachment: FAttachment, return (
-
+

@@ -179,12 +180,30 @@ function AttachmentInfo({ attachment, isFullDetail }: { attachment: FAttachment,

+ {attachment.utcDateScheduledForErasureSince && }
) } +function DeletionAlert({ utcDateScheduledForErasureSince }: { utcDateScheduledForErasureSince: string }) { + const scheduledSinceTimestamp = utils.parseDate(utcDateScheduledForErasureSince)?.getTime(); + // use default value (30 days in seconds) from options_init as fallback, in case getInt returns null + const intervalMs = options.getInt("eraseUnusedAttachmentsAfterSeconds") || 2592000 * 1000; + const deletionTimestamp = scheduledSinceTimestamp + intervalMs; + const willBeDeletedInMs = deletionTimestamp - Date.now(); + + return ( + + { willBeDeletedInMs >= 60000 + ? t("attachment_detail_2.will_be_deleted_in", { time: utils.formatTimeInterval(willBeDeletedInMs) }) + : t("attachment_detail_2.will_be_deleted_soon")} + {t("attachment_detail_2.deletion_reason")} + + ) +} + function AttachmentActions({ attachment, copyAttachmentLinkToClipboard }: { attachment: FAttachment, copyAttachmentLinkToClipboard: () => void }) { const isElectron = utils.isElectron(); const fileUploadRef = useRef(null);