mirror of
https://github.com/zadam/trilium.git
synced 2025-12-17 05:39:55 +01:00
refactor(toast): get rid of autohide
This commit is contained in:
@@ -8,7 +8,6 @@ export interface ToastOptions {
|
|||||||
title?: string;
|
title?: string;
|
||||||
message: string;
|
message: string;
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
autohide?: boolean;
|
|
||||||
progress?: number;
|
progress?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,7 +18,6 @@ function showPersistent(options: ToastOptionsWithRequiredId) {
|
|||||||
if (existingToast) {
|
if (existingToast) {
|
||||||
updateToast(options.id, options);
|
updateToast(options.id, options);
|
||||||
} else {
|
} else {
|
||||||
options.autohide = false;
|
|
||||||
addToast(options);
|
addToast(options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -34,7 +32,6 @@ function showMessage(message: string, timeout = 2000, icon = "bx bx-check") {
|
|||||||
addToast({
|
addToast({
|
||||||
icon,
|
icon,
|
||||||
message,
|
message,
|
||||||
autohide: true,
|
|
||||||
timeout
|
timeout
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -45,7 +42,6 @@ export function showError(message: string, timeout = 10000) {
|
|||||||
addToast({
|
addToast({
|
||||||
icon: "bx bx-error-circle",
|
icon: "bx bx-error-circle",
|
||||||
message,
|
message,
|
||||||
autohide: true,
|
|
||||||
timeout
|
timeout
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -57,7 +53,6 @@ function showErrorTitleAndMessage(title: string, message: string, timeout = 1000
|
|||||||
title,
|
title,
|
||||||
icon: "bx bx-error-circle",
|
icon: "bx bx-error-circle",
|
||||||
message,
|
message,
|
||||||
autohide: true,
|
|
||||||
timeout
|
timeout
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,13 +17,12 @@ export default function ToastContainer() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function Toast({ id, title, autohide, timeout, progress, message, icon }: ToastOptionsWithRequiredId) {
|
function Toast({ id, title, timeout, progress, message, icon }: ToastOptionsWithRequiredId) {
|
||||||
// Autohide.
|
// Autohide.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!autohide || !id) return;
|
|
||||||
const timerId = setTimeout(() => removeToastFromStore(id), timeout || DEFAULT_DELAY);
|
const timerId = setTimeout(() => removeToastFromStore(id), timeout || DEFAULT_DELAY);
|
||||||
return () => clearTimeout(timerId);
|
return () => clearTimeout(timerId);
|
||||||
}, [ autohide, id, timeout ]);
|
}, [ id, timeout ]);
|
||||||
|
|
||||||
const closeButton = <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close" />;
|
const closeButton = <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close" />;
|
||||||
const toastIcon = <Icon icon={icon.startsWith("bx ") ? icon : `bx bx-${icon}`} />;
|
const toastIcon = <Icon icon={icon.startsWith("bx ") ? icon : `bx bx-${icon}`} />;
|
||||||
|
|||||||
Reference in New Issue
Block a user