qbit_manage/web-ui/js/utils/toast.js
bobokun 3fa5fcee3b
v4.5.0 (#862)
# Requirements Updated
- fastapi==0.116.0
- retrying==1.4.0
- uvicorn==0.35.0

# New Features
- **Web UI**: Introduced a new Web UI for configuring and managing qBit
Manage.
  - Visual Configuration Editor for YAML files.
  - Command Execution directly from the UI.
  - Undo/Redo History for changes.
  - Theme Support (light/dark mode).
  - Responsive Design for desktop and mobile.
  - Real-time YAML Preview.
- Pass skip qbitorrent check as optional parameter to the API (Adds
#860)\


**Full Changelog**:
https://github.com/StuffAnThings/qbit_manage/compare/v4.4.0...v4.5.0

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: ineednewpajamas <73252768+ineednewpajamas@users.noreply.github.com>
2025-07-11 19:13:41 -04:00

71 lines
2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Toast Utility Module
* Manages the display of toast notifications.
*/
import { get, show, hide } from './dom.js';
import { CLOSE_ICON_SVG } from './icons.js';
const TOAST_CONTAINER_ID = 'toast-container';
/**
* Displays a toast notification.
* @param {string} message - The message to display in the toast.
* @param {'success'|'error'|'warning'|'info'} [type='info'] - The type of toast (for styling).
* @param {number} [duration=5000] - How long the toast should be visible in milliseconds.
*/
export function showToast(message, type = 'info', duration = 5000) {
const container = get(TOAST_CONTAINER_ID);
if (!container) {
console.warn('Toast container not found. Cannot display toast message.');
return;
}
const toast = document.createElement('div');
toast.className = `toast toast-${type}`;
const icons = {
success: '✓',
error: '✕',
warning: '⚠',
info: '',
undo: '↶',
redo: '↷'
};
toast.innerHTML = `
<div class="toast-icon">${icons[type] || icons.info}</div>
<div class="toast-content">
<div class="toast-message">${message}</div>
</div>
<button class="btn btn-icon btn-close-icon toast-close">
${CLOSE_ICON_SVG}
</button>
`;
container.appendChild(toast);
// Show toast (add 'show' class to trigger transition)
setTimeout(() => {
toast.classList.add('show');
}, 100);
// Auto-hide toast
const hideToast = () => {
toast.classList.remove('show');
// Remove from DOM after transition
toast.addEventListener('transitionend', () => {
if (toast.parentElement) {
toast.remove();
}
}, { once: true });
};
setTimeout(hideToast, duration);
// Close button event
const closeButton = toast.querySelector('.toast-close');
if (closeButton) {
closeButton.addEventListener('click', hideToast);
}
}