Add custom homelab dashboard stack
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { fetchDashboardData } from "./api.js";
|
||||
import { getState, setError, subscribe, updateData } from "./state.js";
|
||||
import { renderHeader } from "./renderers/header.js";
|
||||
import { renderQuickAccess } from "./renderers/quick-access.js";
|
||||
import { renderServices } from "./renderers/services.js";
|
||||
import { renderStats } from "./renderers/stats.js";
|
||||
import { renderStorage } from "./renderers/storage.js";
|
||||
|
||||
let pollTimer = null;
|
||||
|
||||
function render(state) {
|
||||
renderHeader(state);
|
||||
renderStats(state);
|
||||
renderStorage(state);
|
||||
renderServices(state);
|
||||
}
|
||||
|
||||
async function refreshData() {
|
||||
try {
|
||||
const payload = await fetchDashboardData();
|
||||
updateData(payload);
|
||||
} catch (error) {
|
||||
console.error("Dashboard refresh failed", error);
|
||||
setError(error instanceof Error ? error : new Error("Unknown dashboard refresh error"));
|
||||
} finally {
|
||||
restartPolling();
|
||||
}
|
||||
}
|
||||
|
||||
function restartPolling() {
|
||||
if (pollTimer) {
|
||||
window.clearInterval(pollTimer);
|
||||
}
|
||||
const state = window.__dashboardState?.() ?? null;
|
||||
const interval = state?.refreshIntervalMs ?? 20000;
|
||||
pollTimer = window.setInterval(refreshData, interval);
|
||||
}
|
||||
|
||||
subscribe((state) => {
|
||||
window.__dashboardState = () => state;
|
||||
render(state);
|
||||
});
|
||||
|
||||
renderQuickAccess();
|
||||
refreshData();
|
||||
window.setInterval(() => renderHeader(getState()), 1000);
|
||||
Reference in New Issue
Block a user