Add client-side handler for history-update SSE events
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
import { state, SSE_RECONNECT_MS } from './state.js';
|
import { state, SSE_RECONNECT_MS } from './state.js';
|
||||||
import { renderDownloads } from './ui/downloads.js';
|
import { renderDownloads } from './ui/downloads.js';
|
||||||
import { hideError, hideLoading } from './ui/auth.js';
|
import { hideError, hideLoading } from './ui/auth.js';
|
||||||
|
import { loadHistory } from './ui/history.js';
|
||||||
|
|
||||||
export function startSSE() {
|
export function startSSE() {
|
||||||
stopSSE();
|
stopSSE();
|
||||||
@@ -33,6 +34,19 @@ export function startSSE() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Listen for history-update events from server
|
||||||
|
source.addEventListener('history-update', (event) => {
|
||||||
|
try {
|
||||||
|
const data = JSON.parse(event.data);
|
||||||
|
console.log('[SSE] History update received:', data.type);
|
||||||
|
// Trigger history reload
|
||||||
|
const historyReloadEvent = new CustomEvent('historyReload');
|
||||||
|
document.dispatchEvent(historyReloadEvent);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('[SSE] Failed to parse history-update message:', err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
source.onerror = () => {
|
source.onerror = () => {
|
||||||
// EventSource retries automatically; we just log and show a reconnecting indicator
|
// EventSource retries automatically; we just log and show a reconnecting indicator
|
||||||
console.warn('[SSE] Connection lost, browser will retry...');
|
console.warn('[SSE] Connection lost, browser will retry...');
|
||||||
|
|||||||
Reference in New Issue
Block a user