More reliable refresh that possible can handle app downtime

master
Kuba Orlik 9 months ago
parent 82b9d48c69
commit 669c79f0b7

@ -40,7 +40,11 @@ export default new (class DashboardPage extends StatefulPage<State, typeof actio
}
wrapInLayout(ctx: BaseContext, content: Templatable): Templatable {
return html(ctx, "Dashboard", content, { navbar: () => "" });
if (ctx.headers["just-data"]) {
return content;
} else {
return html(ctx, "Dashboard", content, { navbar: () => "" });
}
}
render(ctx: BaseContext, state: State, inputs: Record<string, string>) {
@ -75,13 +79,24 @@ export default new (class DashboardPage extends StatefulPage<State, typeof actio
</tbody>
</table>
{
/* HTML */ `<script>
setInterval(function () {
document.location = document.location;
}, 15 * 1000);
</script>`
}
{ctx.headers["just-data"]
? ""
: /* HTML */ `<script>
function refresh() {
let xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.open("GET", "/dashboard");
xhr.setRequestHeader("just-data", "true");
xhr.onload = function () {
document.querySelector("body").innerHTML =
xhr.response;
};
xhr.send();
}
setInterval(refresh, 15 * 1000);
</script>`}
</div>
);
}

Loading…
Cancel
Save