mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-02 19:36:12 +01:00 
			
		
		
		
	import uses persistent toasts
This commit is contained in:
		@@ -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);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
}
 | 
			
		||||
@@ -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({
 | 
			
		||||
 
 | 
			
		||||
@@ -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">
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user