cleanup alpine

frdel committed Aug 1, 2025 at 20:39 UTC f7dee3470f76ea5af34c78017fca3ed932640f4b
1 file changed +28 -39
webui/index.js
+28 -39
@@ -4,6 +4,7 @@ import * as api from "./js/api.js";
4 import * as css from "./js/css.js";
5 import { sleep } from "./js/sleep.js";
6 import { store as attachmentsStore } from "./components/chat/attachments/attachmentsStore.js";
7 +import { store as notificationStore } from "./components/notifications/notification-store.js";
8
9 window.fetchApi = api.fetchApi; // TODO - backward compatibility for non-modular scripts, remove once refactored to alpine
10
@@ -172,14 +173,15 @@ function toastFetchError(text, error) {
173
174 if (getConnectionStatus()) {
175 // Backend is connected, just show the error
175 - toastFrontendError(`${text}: ${errorMessage}`).catch(e =>
176 - console.error('Failed to show error toast:', e)
176 + toastFrontendError(`${text}: ${errorMessage}`).catch((e) =>
177 + console.error("Failed to show error toast:", e)
178 );
179 } else {
180 // Backend is disconnected, show connection error
180 - toastFrontendError(`${text} (backend appears to be disconnected): ${errorMessage}`, "Connection Error").catch(e =>
181 - console.error('Failed to show connection error toast:', e)
182 - );
181 + toastFrontendError(
182 + `${text} (backend appears to be disconnected): ${errorMessage}`,
183 + "Connection Error"
184 + ).catch((e) => console.error("Failed to show connection error toast:", e));
185 }
186 }
187 window.toastFetchError = toastFetchError;
@@ -337,7 +339,7 @@ async function poll() {
339
340 const response = await sendJsonData("/poll", {
341 log_from: lastLogVersion,
340 - notifications_from: globalThis.Alpine?.store('notificationStore')?.lastNotificationVersion || 0,
342 + notifications_from: notificationStore.lastNotificationVersion || 0,
343 context: context || null,
344 timezone: timezone,
345 });
@@ -378,19 +380,7 @@ async function poll() {
380 updateProgress(response.log_progress, response.log_progress_active);
381
382 // Update notifications from response
381 - if (globalThis.Alpine?.store('notificationStore')) {
382 - const notificationStore = globalThis.Alpine.store('notificationStore');
383 -
384 - // Ensure store is initialized
385 - if (!notificationStore.lastNotificationGuid && response.notifications_guid) {
386 - console.log('Initializing notification store on fresh load');
387 - notificationStore.initialize();
388 - }
389 -
390 - notificationStore.updateFromPoll(response);
391 - } else {
392 - console.warn('Notification store not available during poll');
393 - }
383 + notificationStore.updateFromPoll(response);
384
385 //set ui model vars from backend
386 if (window.Alpine && inputSection) {
@@ -812,7 +802,10 @@ window.nudge = async function () {
802 window.restart = async function () {
803 try {
804 if (!getConnectionStatus()) {
815 - await toastFrontendError("Backend disconnected, cannot restart.", "Restart Error");
805 + await toastFrontendError(
806 + "Backend disconnected, cannot restart.",
807 + "Restart Error"
808 + );
809 return;
810 }
811 // First try to initiate restart
@@ -839,7 +832,12 @@ window.restart = async function () {
832 }
833
834 // If we get here, restart failed or took too long
842 - await toastFrontendError("Restart timed out or failed", "Restart Error", 8, "restart");
835 + await toastFrontendError(
836 + "Restart timed out or failed",
837 + "Restart Error",
838 + 8,
839 + "restart"
840 + );
841 }
842 };
843
@@ -971,24 +969,18 @@ function toast(text, type = "info", timeout = 5000) {
969 const display_time = Math.max(timeout / 1000, 3); // Minimum 3 seconds
970
971 // Use new frontend notification system based on type
974 - if (window.Alpine && window.Alpine.store && window.Alpine.store('notificationStore')) {
975 - const store = window.Alpine.store('notificationStore');
972 switch (type.toLowerCase()) {
977 - case 'error':
978 - return store.frontendError(text, "Error", display_time);
979 - case 'success':
980 - return store.frontendInfo(text, "Success", display_time);
981 - case 'warning':
982 - return store.frontendWarning(text, "Warning", display_time);
983 - case 'info':
973 + case "error":
974 + return notificationStore.frontendError(text, "Error", display_time);
975 + case "success":
976 + return notificationStore.frontendInfo(text, "Success", display_time);
977 + case "warning":
978 + return notificationStore.frontendWarning(text, "Warning", display_time);
979 + case "info":
980 default:
985 - return store.frontendInfo(text, "Info", display_time);
981 + return notificationStore.frontendInfo(text, "Info", display_time);
982 }
987 - } else {
988 - // Fallback if Alpine/store not ready
989 - console.log(`${type.toUpperCase()}: ${text}`);
990 - return null;
991 - }
983 +
984 }
985 window.toast = toast;
986
@@ -1049,14 +1041,11 @@ async function startPolling() {
1041
1042 document.addEventListener("DOMContentLoaded", startPolling);
1043
1052 -
1044 // Setup event handlers once the DOM is fully loaded
1045 document.addEventListener("DOMContentLoaded", function () {
1046 setupSidebarToggle();
1047 setupTabs();
1048 initializeActiveTab();
1058 -
1059 -
1049 });
1050
1051 // Setup tabs functionality