Agent Zero AI framework
fix: toast handling, mobile breakpoint
Alessandro7c2866ca614f
diff --git a/webui/css/toast.css b/webui/css/toast.cssindex 9ecf346dc..f28fbe0bc 100644--- a/webui/css/toast.css+++ b/webui/css/toast.css@@ -9,8 +9,8 @@display: none;align-items: center;z-index: 1000;- transform: translateY(100%) scale(0.98);- transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);+ transform: translateY(100%);+ transition: transform 0.4s cubic-bezier(0.19, 0.86, 0.47, 1), background-color 0.3s ease;will-change: transform;}@@ -43,11 +43,11 @@#toast.show {display: flex;- transform: translateY(0) scale(1);+ transform: translateY(0);}#toast.hide {- transform: translateY(100%) scale(0.98);+ transform: translateY(100%);}#toast.toast--success {@@ -71,6 +71,13 @@cursor: pointer;font-size: 16px;margin-left: 8px;+ opacity: 0.8;+ transition: opacity 0.2s ease;+}++.toast__close:hover,+.toast__copy:hover {+ opacity: 1;}/* Animations */diff --git a/webui/index.css b/webui/index.cssindex e6b069aec..9b86d7d8e 100644--- a/webui/index.css+++ b/webui/index.css@@ -1535,7 +1535,7 @@ input:checked + .slider:before {}/* Media Queries */-@media (max-width: 510px) {+@media (max-width: 640px) {.text-buttons-row {display: table;gap: 0.1rem !important;@@ -1590,7 +1590,7 @@ input:checked + .slider:before {}}-@media (max-width: 600px) {+@media (max-width: 640px) {#chat-input {min-height: 5.3rem;align-content: start;diff --git a/webui/index.js b/webui/index.jsindex 848552e2c..cf0975182 100644--- a/webui/index.js+++ b/webui/index.js@@ -499,22 +499,35 @@ window.nudge = async function () {window.restart = async function () {try {+ // First try to initiate restartconst resp = await sendJsonData("/restart", {});} catch (e) {- //error expected here- toast("Restarting...", "info", 0)- while (true) {+ // Show restarting message+ toast("Restarting...", "info", 0);++ let retries = 0;+ const maxRetries = 60; // Maximum number of retries (15 seconds with 250ms interval)++ while (retries < maxRetries) {try {- // try health check until server is back up againconst resp = await sendJsonData("/health", {});+ // Server is back up, show success messageawait new Promise(resolve => setTimeout(resolve, 250));- toast("Restarted", "success", 2000)+ hideToast();+ await new Promise(resolve => setTimeout(resolve, 400));+ toast("Restarted", "success", 5000);return;} catch (e) {- continue;+ // Server still down, keep waiting+ retries++;+ await new Promise(resolve => setTimeout(resolve, 250));}}-++ // If we get here, restart failed or took too long+ hideToast();+ await new Promise(resolve => setTimeout(resolve, 400));+ toast("Restart timed out or failed", "error", 5000);}}@@ -681,66 +694,92 @@ function removeClassFromElement(element, className) {function toast(text, type = 'info', timeout = 5000) {const toast = document.getElementById('toast');- const isVisible = toast.style.display === 'flex';+ const isVisible = toast.classList.contains('show');- // Update the toast content and type- const title = type.charAt(0).toUpperCase() + type.slice(1);- toast.querySelector('.toast__title').textContent = title;- toast.querySelector('.toast__message').textContent = text;- toast.className = `toast toast--${type}`;+ // Clear any existing timeout immediately+ if (toast.timeoutId) {+ clearTimeout(toast.timeoutId);+ toast.timeoutId = null;+ }- // Show/hide copy button based on toast type- const copyButton = toast.querySelector('.toast__copy');- copyButton.style.display = type === 'error' ? 'inline-block' : 'none';+ // Function to update toast content and show it+ const updateAndShowToast = () => {+ // Update the toast content and type+ const title = type.charAt(0).toUpperCase() + type.slice(1);+ toast.querySelector('.toast__title').textContent = title;+ toast.querySelector('.toast__message').textContent = text;- // Add the close button event listener- const closeButton = toast.querySelector('.toast__close');- closeButton.onclick = () => {- hideToast();- };+ // Remove old classes and add new ones+ toast.classList.remove('toast--success', 'toast--error', 'toast--info');+ toast.classList.add(`toast--${type}`);- // Add the copy button event listener- copyButton.onclick = () => {- navigator.clipboard.writeText(text);- copyButton.textContent = 'Copied!';- setTimeout(() => {- copyButton.textContent = 'Copy';- }, 2000);- };+ // Show/hide copy button based on toast type+ const copyButton = toast.querySelector('.toast__copy');+ copyButton.style.display = type === 'error' ? 'inline-block' : 'none';++ // Add the close button event listener+ const closeButton = document.querySelector('.toast__close');+ closeButton.onclick = () => {+ hideToast();+ };- // Only trigger animation if toast is not already visible- if (!isVisible) {- // Remove any existing animation classes- toast.classList.remove('show', 'hide');+ // Add the copy button event listener+ copyButton.onclick = () => {+ navigator.clipboard.writeText(text);+ copyButton.textContent = 'Copied!';+ setTimeout(() => {+ copyButton.textContent = 'Copy';+ }, 2000);+ };- // Show the toast and trigger animation+ // Show the toasttoast.style.display = 'flex';// Force a reflow to ensure the animation triggersvoid toast.offsetWidth;toast.classList.add('show');- }- // Clear any existing timeout- if (toast.timeoutId)- clearTimeout(toast.timeoutId);+ // Set timeout if specified+ if (timeout) {+ const minTimeout = Math.max(timeout, 5000);+ toast.timeoutId = setTimeout(() => {+ hideToast();+ }, minTimeout);+ }+ };- // Automatically close the toast after specified timeout- if (timeout)- toast.timeoutId = setTimeout(() => {- hideToast();- }, timeout);+ if (isVisible) {+ // If a toast is visible, hide it first then show the new one+ toast.classList.remove('show');+ toast.classList.add('hide');++ // Wait for hide animation to complete before showing new toast+ setTimeout(() => {+ toast.classList.remove('hide');+ updateAndShowToast();+ }, 400); // Match this with CSS transition duration+ } else {+ // If no toast is visible, show the new one immediately+ updateAndShowToast();+ }}function hideToast() {const toast = document.getElementById('toast');++ // Clear any existing timeout+ if (toast.timeoutId) {+ clearTimeout(toast.timeoutId);+ toast.timeoutId = null;+ }+toast.classList.remove('show');toast.classList.add('hide');- // Remove the element from display after animation completes+ // Wait for the hide animation to complete before removing from displaysetTimeout(() => {toast.style.display = 'none';toast.classList.remove('hide');- }, 300); // Match this with animation duration+ }, 400); // Match this with CSS transition duration}function scrollChanged(isAtBottom) {