Skip to content

Build your personal knowledge base with Trilium Notes

client-ts: Port services/toast

Elian Dorancf57819b2241
diff --git a/src/public/app/services/toast.js b/src/public/app/services/toast.ts
similarity index 78%
rename from src/public/app/services/toast.js
rename to src/public/app/services/toast.ts
index 09c17ce7f3..13deb3bfcb 100644
--- a/src/public/app/services/toast.js
+++ b/src/public/app/services/toast.ts
@@ -1,7 +1,17 @@
import ws from "./ws.js";
import utils from "./utils.js";
-function toast(options) {
+interface ToastOptions {
+ id?: string;
+ icon: string;
+ title: string;
+ message: string;
+ delay?: number;
+ autohide?: boolean;
+ closeAfter?: number;
+}
+
+function toast(options: ToastOptions) {
const $toast = $(`<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<strong class="mr-auto"><span class="bx bx-${options.icon}"></span> <span class="toast-title"></span></strong>
@@ -33,7 +43,7 @@ function toast(options) {
return $toast;
}
-function showPersistent(options) {
+function showPersistent(options: ToastOptions) {
let $toast = $(`#toast-${options.id}`);
if ($toast.length > 0) {
@@ -50,11 +60,11 @@ function showPersistent(options) {
}
}
-function closePersistent(id) {
+function closePersistent(id: string) {
$(`#toast-${id}`).remove();
}
-function showMessage(message, delay = 2000) {
+function showMessage(message: string, delay = 2000) {
console.debug(utils.now(), "message:", message);
toast({
@@ -66,13 +76,13 @@ function showMessage(message, delay = 2000) {
});
}
-function showAndLogError(message, delay = 10000) {
+function showAndLogError(message: string, delay = 10000) {
showError(message, delay);
ws.logError(message);
}
-function showError(message, delay = 10000) {
+function showError(message: string, delay = 10000) {
console.log(utils.now(), "error: ", message);
toast({
@@ -84,7 +94,7 @@ function showError(message, delay = 10000) {
});
}
-function showErrorTitleAndMessage(title, message, delay = 10000) {
+function showErrorTitleAndMessage(title: string, message: string, delay = 10000) {
console.log(utils.now(), "error: ", message);
toast({
@@ -96,7 +106,7 @@ function showErrorTitleAndMessage(title, message, delay = 10000) {
});
}
-function throwError(message) {
+function throwError(message: string) {
ws.logError(message);
throw new Error(message);