mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 11:02:28 +08:00
client-ts: Port services/toast
This commit is contained in:
parent
78f929ee69
commit
cf57819b22
@ -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);
|
Loading…
x
Reference in New Issue
Block a user