mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
import uses persistent toasts
This commit is contained in:
parent
8886e95847
commit
992d174b23
@ -39,17 +39,29 @@ export async function uploadFiles(parentNoteId, files, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ws.subscribeToMessages(async message => {
|
ws.subscribeToMessages(async message => {
|
||||||
|
const toast = {
|
||||||
|
id: "import",
|
||||||
|
title: "Import",
|
||||||
|
icon: "plus"
|
||||||
|
};
|
||||||
|
|
||||||
if (message.type === 'import-error') {
|
if (message.type === 'import-error') {
|
||||||
|
infoService.closePersistent(toast.id);
|
||||||
infoService.showError(message.message);
|
infoService.showError(message.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.type === 'import-progress-count') {
|
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') {
|
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);
|
await treeService.reloadNote(message.parentNoteId);
|
||||||
|
|
||||||
|
@ -14,11 +14,43 @@ function toast(options) {
|
|||||||
</div>
|
</div>
|
||||||
</div>`);
|
</div>`);
|
||||||
|
|
||||||
|
if (options.id) {
|
||||||
|
$toast.attr("id", "toast-" + options.id);
|
||||||
|
}
|
||||||
|
|
||||||
$("#toast-container").append($toast);
|
$("#toast-container").append($toast);
|
||||||
|
|
||||||
$toast.toast({
|
$toast.toast({
|
||||||
delay: options.delay
|
delay: options.delay || 3000,
|
||||||
}).toast("show");
|
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) {
|
function showMessage(message, delay = 3000) {
|
||||||
@ -28,6 +60,7 @@ function showMessage(message, delay = 3000) {
|
|||||||
title: "Info",
|
title: "Info",
|
||||||
icon: "check",
|
icon: "check",
|
||||||
message: message,
|
message: message,
|
||||||
|
autohide: true,
|
||||||
delay
|
delay
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -45,6 +78,7 @@ function showError(message, delay = 10000) {
|
|||||||
title: "Error",
|
title: "Error",
|
||||||
icon: 'alert',
|
icon: 'alert',
|
||||||
message: message,
|
message: message,
|
||||||
|
autohide: true,
|
||||||
delay
|
delay
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -59,5 +93,7 @@ export default {
|
|||||||
showMessage,
|
showMessage,
|
||||||
showError,
|
showError,
|
||||||
showAndLogError,
|
showAndLogError,
|
||||||
throwError
|
throwError,
|
||||||
|
showPersistent,
|
||||||
|
closePersistent
|
||||||
}
|
}
|
@ -33,7 +33,7 @@ class ImportContext {
|
|||||||
async increaseProgressCount() {
|
async increaseProgressCount() {
|
||||||
this.progressCount++;
|
this.progressCount++;
|
||||||
|
|
||||||
if (Date.now() - this.lastSentCountTs >= 1000) {
|
if (Date.now() - this.lastSentCountTs >= 300) {
|
||||||
this.lastSentCountTs = Date.now();
|
this.lastSentCountTs = Date.now();
|
||||||
|
|
||||||
await ws.sendMessageToAllClients({
|
await ws.sendMessageToAllClients({
|
||||||
|
@ -8,6 +8,9 @@
|
|||||||
</head>
|
</head>
|
||||||
<body class="mobile">
|
<body class="mobile">
|
||||||
<noscript>Trilium requires JavaScript to be enabled.</noscript>
|
<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 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">
|
<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">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user