Skip to content

Build your personal knowledge base with Trilium Notes

chore(client/ts): port services/protected_session

Elian Doranf7dc9ea8e4df
diff --git a/src/public/app/services/protected_session.js b/src/public/app/services/protected_session.ts
similarity index 85%
rename from src/public/app/services/protected_session.js
rename to src/public/app/services/protected_session.ts
index e221e0d202..0b6b03c9d3 100644
--- a/src/public/app/services/protected_session.js
+++ b/src/public/app/services/protected_session.ts
@@ -1,6 +1,7 @@
import server from './server.js';
import protectedSessionHolder from './protected_session_holder.js';
import toastService from "./toast.js";
+import type { ToastOptions } from "./toast.js";
import ws from "./ws.js";
import appContext from "../components/app_context.js";
import froca from "./froca.js";
@@ -8,7 +9,19 @@ import utils from "./utils.js";
import options from "./options.js";
import { t } from './i18n.js';
-let protectedSessionDeferred = null;
+let protectedSessionDeferred: JQuery.Deferred<any, any, any> | null = null;
+
+// TODO: Deduplicate with server when possible.
+interface Response {
+ success: boolean;
+}
+
+interface Message {
+ taskId: string;
+ data: {
+ protect: boolean
+ }
+}
async function leaveProtectedSession() {
if (protectedSessionHolder.isProtectedSessionAvailable()) {
@@ -44,11 +57,11 @@ async function reloadData() {
await froca.loadInitialTree();
// make sure that all notes used in the application are loaded, including the ones not shown in the tree
- await froca.reloadNotes(allNoteIds, true);
+ await froca.reloadNotes(allNoteIds);
}
-async function setupProtectedSession(password) {
- const response = await server.post('login/protected', { password: password });
+async function setupProtectedSession(password: string) {
+ const response = await server.post<Response>('login/protected', { password: password });
if (!response.success) {
toastService.showError(t("protected_session.wrong_password"), 3000);
@@ -80,13 +93,13 @@ ws.subscribeToMessages(async message => {
}
});
-async function protectNote(noteId, protect, includingSubtree) {
+async function protectNote(noteId: string, protect: boolean, includingSubtree: boolean) {
await enterProtectedSession();
await server.put(`notes/${noteId}/protect/${protect ? 1 : 0}?subtree=${includingSubtree ? 1 : 0}`);
}
-function makeToast(message, title, text) {
+function makeToast(message: Message, title: string, text: string): ToastOptions {
return {
id: message.taskId,
title,
diff --git a/src/public/app/services/toast.ts b/src/public/app/services/toast.ts
index ba1cde2592..9b6e4f64ce 100644
--- a/src/public/app/services/toast.ts
+++ b/src/public/app/services/toast.ts
@@ -1,7 +1,7 @@
import ws from "./ws.js";
import utils from "./utils.js";
-interface ToastOptions {
+export interface ToastOptions {
id?: string;
icon: string;
title: string;