From 992d174b23318d840f27f3a66e60229a9b58dac7 Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 17 Oct 2019 20:44:51 +0200 Subject: [PATCH] import uses persistent toasts --- src/public/javascripts/services/import.js | 16 +++++++-- src/public/javascripts/services/info.js | 42 +++++++++++++++++++++-- src/services/import_context.js | 2 +- src/views/mobile.ejs | 3 ++ 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/src/public/javascripts/services/import.js b/src/public/javascripts/services/import.js index ab100d303..451b92405 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.js index 6aec2e789..029b54509 100644 --- a/src/public/javascripts/services/info.js +++ b/src/public/javascripts/services/info.js @@ -14,11 +14,43 @@ function toast(options) { `); + 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 file diff --git a/src/services/import_context.js b/src/services/import_context.js index a4961fa28..77980fd68 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.ejs index 80fc7a920..217093173 100644 --- a/src/views/mobile.ejs +++ b/src/views/mobile.ejs @@ -8,6 +8,9 @@ + +
+