diff --git a/src/public/app/widgets/type_widgets/file.js b/src/public/app/widgets/type_widgets/file.ts
similarity index 76%
rename from src/public/app/widgets/type_widgets/file.js
rename to src/public/app/widgets/type_widgets/file.ts
index 5454b7a8f..b4a7d4aeb 100644
--- a/src/public/app/widgets/type_widgets/file.js
+++ b/src/public/app/widgets/type_widgets/file.ts
@@ -1,6 +1,8 @@
import openService from "../../services/open.js";
import TypeWidget from "./type_widget.js";
import { t } from "../../services/i18n.js";
+import type { EventData } from "../../components/app_context.js";
+import type FNote from "../../entities/fnote.js";
const TPL = `
@@ -8,7 +10,7 @@ const TPL = `
.type-file .note-detail {
height: 100%;
}
-
+
.note-detail-file {
padding: 10px;
height: 100%;
@@ -22,21 +24,28 @@ const TPL = `
margin: 10px;
}
-
+
-
+
${t("file.file_preview_not_available")}
-
+
-
+
-
+
`;
export default class FileTypeWidget extends TypeWidget {
+
+ private $previewContent!: JQuery;
+ private $previewNotAvailable!: JQuery;
+ private $pdfPreview!: JQuery;
+ private $videoPreview!: JQuery;
+ private $audioPreview!: JQuery;
+
static getType() {
return "file";
}
@@ -52,10 +61,10 @@ export default class FileTypeWidget extends TypeWidget {
super.doRender();
}
- async doRefresh(note) {
+ async doRefresh(note: FNote) {
this.$widget.show();
- const blob = await this.note.getBlob();
+ const blob = await this.note?.getBlob();
this.$previewContent.empty().hide();
this.$pdfPreview.attr("src", "").empty().hide();
@@ -63,7 +72,7 @@ export default class FileTypeWidget extends TypeWidget {
this.$videoPreview.hide();
this.$audioPreview.hide();
- if (blob.content) {
+ if (blob?.content) {
this.$previewContent.show().scrollTop(0);
this.$previewContent.text(blob.content);
} else if (note.mime === "application/pdf") {
@@ -72,20 +81,20 @@ export default class FileTypeWidget extends TypeWidget {
this.$videoPreview
.show()
.attr("src", openService.getUrlForDownload(`api/notes/${this.noteId}/open-partial`))
- .attr("type", this.note.mime)
- .css("width", this.$widget.width());
+ .attr("type", this.note?.mime ?? "")
+ .css("width", this.$widget.width() ?? 0);
} else if (note.mime.startsWith("audio/")) {
this.$audioPreview
.show()
.attr("src", openService.getUrlForDownload(`api/notes/${this.noteId}/open-partial`))
- .attr("type", this.note.mime)
- .css("width", this.$widget.width());
+ .attr("type", this.note?.mime ?? "")
+ .css("width", this.$widget.width() ?? 0);
} else {
this.$previewNotAvailable.show();
}
}
- async entitiesReloadedEvent({ loadResults }) {
+ async entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
if (loadResults.isNoteReloaded(this.noteId)) {
this.refresh();
}