diff --git a/src/public/app/services/import.ts b/src/public/app/services/import.ts index 0c6c25f11..453449e3c 100644 --- a/src/public/app/services/import.ts +++ b/src/public/app/services/import.ts @@ -6,15 +6,15 @@ import appContext from "../components/app_context.js"; import { t } from "./i18n.js"; interface UploadFilesOptions { - safeImport: boolean; - shrinkImages: boolean; - textImportedAsText: boolean; - codeImportedAsCode: boolean; - explodeArchives: boolean; - replaceUnderscoresWithSpaces: boolean; + safeImport?: boolean; + shrinkImages: "true" | "false"; + textImportedAsText?: boolean; + codeImportedAsCode?: boolean; + explodeArchives?: boolean; + replaceUnderscoresWithSpaces?: boolean; } -export async function uploadFiles(entityType: string, parentNoteId: string, files: string[], options: UploadFilesOptions) { +export async function uploadFiles(entityType: string, parentNoteId: string, files: string[] | File[], options: UploadFilesOptions) { if (!["notes", "attachments"].includes(entityType)) { throw new Error(`Unrecognized import entity type '${entityType}'.`); } diff --git a/src/public/app/widgets/dialogs/protected_session_password.js b/src/public/app/widgets/dialogs/protected_session_password.ts similarity index 89% rename from src/public/app/widgets/dialogs/protected_session_password.js rename to src/public/app/widgets/dialogs/protected_session_password.ts index 600a0f165..abc383624 100644 --- a/src/public/app/widgets/dialogs/protected_session_password.js +++ b/src/public/app/widgets/dialogs/protected_session_password.ts @@ -27,14 +27,19 @@ const TPL = ` `; export default class ProtectedSessionPasswordDialog extends BasicWidget { + + private modal!: bootstrap.Modal; + private $passwordForm!: JQuery; + private $passwordInput!: JQuery; + doRender() { this.$widget = $(TPL); - this.modal = Modal.getOrCreateInstance(this.$widget); + this.modal = Modal.getOrCreateInstance(this.$widget[0]); this.$passwordForm = this.$widget.find(".protected-session-password-form"); this.$passwordInput = this.$widget.find(".protected-session-password"); this.$passwordForm.on("submit", () => { - const password = this.$passwordInput.val(); + const password = String(this.$passwordInput.val()); this.$passwordInput.val(""); protectedSessionService.setupProtectedSession(password); diff --git a/src/public/app/widgets/dialogs/recent_changes.js b/src/public/app/widgets/dialogs/recent_changes.ts similarity index 86% rename from src/public/app/widgets/dialogs/recent_changes.js rename to src/public/app/widgets/dialogs/recent_changes.ts index 0d3cd9803..9961817b1 100644 --- a/src/public/app/widgets/dialogs/recent_changes.js +++ b/src/public/app/widgets/dialogs/recent_changes.ts @@ -1,6 +1,6 @@ import { formatDateTime } from "../../utils/formatters.js"; import { t } from "../../services/i18n.js"; -import appContext from "../../components/app_context.js"; +import appContext, { type EventData } from "../../components/app_context.js"; import BasicWidget from "../basic_widget.js"; import dialogService from "../../services/dialog.js"; import froca from "../../services/froca.js"; @@ -28,10 +28,23 @@ const TPL = ` `; +// TODO: Deduplicate with server. +interface RecentChangesRow { + noteId: string; + date: string; +} + export default class RecentChangesDialog extends BasicWidget { + + private ancestorNoteId?: string; + + private modal!: bootstrap.Modal; + private $content!: JQuery; + private $eraseDeletedNotesNow!: JQuery; + doRender() { this.$widget = $(TPL); - this.modal = Modal.getOrCreateInstance(this.$widget); + this.modal = Modal.getOrCreateInstance(this.$widget[0]); this.$content = this.$widget.find(".recent-changes-content"); this.$eraseDeletedNotesNow = this.$widget.find(".erase-deleted-notes-now-button"); @@ -44,7 +57,7 @@ export default class RecentChangesDialog extends BasicWidget { }); } - async showRecentChangesEvent({ ancestorNoteId }) { + async showRecentChangesEvent({ ancestorNoteId }: EventData<"showRecentChanges">) { this.ancestorNoteId = ancestorNoteId; await this.refresh(); @@ -57,7 +70,7 @@ export default class RecentChangesDialog extends BasicWidget { this.ancestorNoteId = hoistedNoteService.getHoistedNoteId(); } - const recentChangesRows = await server.get(`recent-changes/${this.ancestorNoteId}`); + const recentChangesRows = await server.get(`recent-changes/${this.ancestorNoteId}`); // preload all notes into cache await froca.getNotes( @@ -110,7 +123,7 @@ export default class RecentChangesDialog extends BasicWidget { } } else { const note = await froca.getNote(change.noteId); - const notePath = note.getBestNotePathString(); + const notePath = note?.getBestNotePathString(); if (notePath) { $noteLink = await linkService.createLink(notePath, { @@ -118,7 +131,7 @@ export default class RecentChangesDialog extends BasicWidget { showNotePath: true }); } else { - $noteLink = $("").text(note.title); + $noteLink = $("").text(note?.title ?? ""); } } @@ -131,9 +144,7 @@ export default class RecentChangesDialog extends BasicWidget { appContext.tabManager.getActiveContext().setNote(change.noteId); } }) - .addClass(() => { - if (change.current_isDeleted) return "deleted-note"; - }) + .toggleClass("deleted-note", !!change.current_isDeleted) .append($("").text(formattedTime).attr("title", change.date)) .append($noteLink.addClass("note-title")) ); @@ -143,7 +154,7 @@ export default class RecentChangesDialog extends BasicWidget { } } - groupByDate(rows) { + groupByDate(rows: RecentChangesRow[]) { const groupedByDate = new Map(); for (const row of rows) { diff --git a/src/public/app/widgets/dialogs/sort_child_notes.js b/src/public/app/widgets/dialogs/sort_child_notes.ts similarity index 96% rename from src/public/app/widgets/dialogs/sort_child_notes.js rename to src/public/app/widgets/dialogs/sort_child_notes.ts index 3253b29c9..5549fadb8 100644 --- a/src/public/app/widgets/dialogs/sort_child_notes.js +++ b/src/public/app/widgets/dialogs/sort_child_notes.ts @@ -1,3 +1,4 @@ +import type { EventData } from "../../components/app_context.js"; import { t } from "../../services/i18n.js"; import server from "../../services/server.js"; import utils from "../../services/utils.js"; @@ -79,6 +80,10 @@ const TPL = `