Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions static/js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,15 @@ function _wireToastSwipe(el) {
el.addEventListener('touchcancel', endSwipe);
}

const TOAST_MIN_DURATION = 2000;
const TOAST_MAX_DURATION = 6000;
const TOAST_MS_PER_CHAR = 50;

function _getDefaultToastDuration(msg) {
const len = String(msg || '').length;
return Math.min(TOAST_MAX_DURATION, Math.max(TOAST_MIN_DURATION, len * TOAST_MS_PER_CHAR));
}

/**
* Show success toast message
*/
Expand All @@ -380,10 +389,10 @@ export function showToast(msg, durationOrOpts) {
toastEl.classList.remove('error');
toastEl.classList.remove('toast-ai-reply-progress', 'toast-ai-reply-result', 'toast-sending', 'toast-message-sent', 'toast-transform-hint');

let duration = 1200, actionLabel = null, onAction = null, actionHint = null, actionIcon = null, leadingIcon = null, toastClass = null, aiReplyProgress = false, aiReplyResult = false;
let duration = _getDefaultToastDuration(msg), actionLabel = null, onAction = null, actionHint = null, actionIcon = null, leadingIcon = null, toastClass = null, aiReplyProgress = false, aiReplyResult = false;
let secondaryLabel = null, onSecondaryAction = null;
if (typeof durationOrOpts === 'object' && durationOrOpts) {
duration = durationOrOpts.duration || 5000;
duration = durationOrOpts.duration || Math.max(_getDefaultToastDuration(msg), 5000);
actionLabel = durationOrOpts.action;
onAction = durationOrOpts.onAction;
// An optional second, plain-text action before the main one.
Expand Down