Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
import uses persistent toasts
zadam992d174b2331
diff --git a/src/public/javascripts/services/import.js b/src/public/javascripts/services/import.jsindex ab100d303d..451b924055 100644--- a/src/public/javascripts/services/import.js+++ b/src/public/javascripts/services/import.js@@ -39,17 +39,29 @@ export async function uploadFiles(parentNoteId, files, options) {}ws.subscribeToMessages(async message => {+ const toast = {+ id: "import",+ title: "Import",+ icon: "plus"+ };+if (message.type === 'import-error') {+ infoService.closePersistent(toast.id);infoService.showError(message.message);return;}if (message.type === 'import-progress-count') {- infoService.showMessage("Import in progress: " + message.progressCount, 1000);+ toast.message = "Import in progress: " + message.progressCount;++ infoService.showPersistent(toast);}if (message.type === 'import-succeeded') {- infoService.showMessage("Import finished successfully.", 5000);+ toast.message = "Import finished successfully.";+ toast.closeAfter = 5000;++ infoService.showPersistent(toast);await treeService.reloadNote(message.parentNoteId);diff --git a/src/public/javascripts/services/info.js b/src/public/javascripts/services/info.jsindex 6aec2e7890..029b545090 100644--- a/src/public/javascripts/services/info.js+++ b/src/public/javascripts/services/info.js@@ -14,11 +14,43 @@ function toast(options) {</div></div>`);+ if (options.id) {+ $toast.attr("id", "toast-" + options.id);+ }+$("#toast-container").append($toast);$toast.toast({- delay: options.delay- }).toast("show");+ delay: options.delay || 3000,+ autohide: !!options.autohide+ });++ $toast.on('hidden.bs.toast', e => e.target.remove());++ $toast.toast("show");++ return $toast;+}++function showPersistent(options) {+ let $toast = $("#toast-" + options.id);++ if ($toast.length > 0) {+ $toast.find('.toast-body').html(options.message);+ }+ else {+ options.autohide = false;++ $toast = toast(options);+ }++ if (options.closeAfter) {+ setTimeout(() => $toast.toast('dispose'), options.closeAfter);+ }+}++function closePersistent(id) {+ $("#toast-persistent-" + id).toast("dispose");}function showMessage(message, delay = 3000) {@@ -28,6 +60,7 @@ function showMessage(message, delay = 3000) {title: "Info",icon: "check",message: message,+ autohide: true,delay});}@@ -45,6 +78,7 @@ function showError(message, delay = 10000) {title: "Error",icon: 'alert',message: message,+ autohide: true,delay});}@@ -59,5 +93,7 @@ export default {showMessage,showError,showAndLogError,- throwError+ throwError,+ showPersistent,+ closePersistent}\ No newline at end of filediff --git a/src/services/import_context.js b/src/services/import_context.jsindex a4961fa287..77980fd682 100644--- a/src/services/import_context.js+++ b/src/services/import_context.js@@ -33,7 +33,7 @@ class ImportContext {async increaseProgressCount() {this.progressCount++;- if (Date.now() - this.lastSentCountTs >= 1000) {+ if (Date.now() - this.lastSentCountTs >= 300) {this.lastSentCountTs = Date.now();await ws.sendMessageToAllClients({diff --git a/src/views/mobile.ejs b/src/views/mobile.ejsindex 80fc7a9208..217093173f 100644--- a/src/views/mobile.ejs+++ b/src/views/mobile.ejs@@ -8,6 +8,9 @@</head><body class="mobile"><noscript>Trilium requires JavaScript to be enabled.</noscript>++<div id="toast-container" class="d-flex flex-column justify-content-center align-items-center"></div>+<div class="row" id="container-row" style="display: none;"><div id="left-pane" class="d-sm-flex d-md-flex d-lg-flex d-xl-flex col-12 col-sm-5 col-md-4 col-lg-4 col-xl-4">