Flip between messages for the update.
This commit is contained in:
@@ -177,6 +177,33 @@ const wsUrl = (process.env.PUBLIC_LIVE_RELOAD_WS_URL ?? import.meta.env.PUBLIC_L
|
|||||||
if (typeof text === 'string' && text.length > 0) bannerTextEl.textContent = text;
|
if (typeof text === 'string' && text.length > 0) bannerTextEl.textContent = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const updatingMessages = [
|
||||||
|
'Updating website',
|
||||||
|
'Reading website sections',
|
||||||
|
'Found section to update',
|
||||||
|
'Updating found section',
|
||||||
|
];
|
||||||
|
let updatingMessageIdx = 0;
|
||||||
|
let updatingTimer = null;
|
||||||
|
|
||||||
|
function stopUpdatingRotation() {
|
||||||
|
if (updatingTimer) {
|
||||||
|
clearInterval(updatingTimer);
|
||||||
|
updatingTimer = null;
|
||||||
|
}
|
||||||
|
updatingMessageIdx = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function startUpdatingRotation() {
|
||||||
|
if (updatingTimer) return;
|
||||||
|
updatingMessageIdx = 0;
|
||||||
|
setBanner(true, updatingMessages[updatingMessageIdx] || 'Updating website');
|
||||||
|
updatingTimer = setInterval(() => {
|
||||||
|
updatingMessageIdx = (updatingMessageIdx + 1) % updatingMessages.length;
|
||||||
|
setBanner(true, updatingMessages[updatingMessageIdx] || 'Updating website');
|
||||||
|
}, 30_000);
|
||||||
|
}
|
||||||
|
|
||||||
function connect() {
|
function connect() {
|
||||||
const ws = new WebSocket(url);
|
const ws = new WebSocket(url);
|
||||||
ws.onmessage = (ev) => {
|
ws.onmessage = (ev) => {
|
||||||
@@ -191,9 +218,15 @@ const wsUrl = (process.env.PUBLIC_LIVE_RELOAD_WS_URL ?? import.meta.env.PUBLIC_L
|
|||||||
|
|
||||||
if (msg.type === 'update_status') {
|
if (msg.type === 'update_status') {
|
||||||
if (msg.phase === 'request_received') setBanner(true, 'Processing update request');
|
if (msg.phase === 'request_received') setBanner(true, 'Processing update request');
|
||||||
else if (msg.phase === 'intent_processing') setBanner(true, 'Processing update request');
|
else if (msg.phase === 'intent_processing') {
|
||||||
else if (msg.phase === 'updating') setBanner(true, 'Updating website');
|
stopUpdatingRotation();
|
||||||
else if (msg.phase === 'update_done') setBanner(false);
|
setBanner(true, 'Processing update request');
|
||||||
|
} else if (msg.phase === 'updating') {
|
||||||
|
startUpdatingRotation();
|
||||||
|
} else if (msg.phase === 'update_done') {
|
||||||
|
stopUpdatingRotation();
|
||||||
|
setBanner(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// ignore
|
// ignore
|
||||||
|
|||||||
Reference in New Issue
Block a user