refactor(toast): get rid of autohide

This commit is contained in:
Elian Doran 2025-12-07 00:07:43 +02:00
parent 7463570e76
commit 21335b1b00
No known key found for this signature in database
2 changed files with 2 additions and 8 deletions

View File

@ -8,7 +8,6 @@ export interface ToastOptions {
title?: string;
message: string;
timeout?: number;
autohide?: boolean;
progress?: number;
}
@ -19,7 +18,6 @@ function showPersistent(options: ToastOptionsWithRequiredId) {
if (existingToast) {
updateToast(options.id, options);
} else {
options.autohide = false;
addToast(options);
}
}
@ -34,7 +32,6 @@ function showMessage(message: string, timeout = 2000, icon = "bx bx-check") {
addToast({
icon,
message,
autohide: true,
timeout
});
}
@ -45,7 +42,6 @@ export function showError(message: string, timeout = 10000) {
addToast({
icon: "bx bx-error-circle",
message,
autohide: true,
timeout
})
}
@ -57,7 +53,6 @@ function showErrorTitleAndMessage(title: string, message: string, timeout = 1000
title,
icon: "bx bx-error-circle",
message,
autohide: true,
timeout
});
}

View File

@ -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.
useEffect(() => {
if (!autohide || !id) return;
const timerId = setTimeout(() => removeToastFromStore(id), timeout || DEFAULT_DELAY);
return () => clearTimeout(timerId);
}, [ autohide, id, timeout ]);
}, [ id, timeout ]);
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}`} />;