More reliable refresh that possible can handle app downtime

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

@ -40,8 +40,12 @@ export default new (class DashboardPage extends StatefulPage<State, typeof actio
} }
wrapInLayout(ctx: BaseContext, content: Templatable): Templatable { wrapInLayout(ctx: BaseContext, content: Templatable): Templatable {
if (ctx.headers["just-data"]) {
return content;
} else {
return html(ctx, "Dashboard", content, { navbar: () => "" }); return html(ctx, "Dashboard", content, { navbar: () => "" });
} }
}
render(ctx: BaseContext, state: State, inputs: Record<string, string>) { render(ctx: BaseContext, state: State, inputs: Record<string, string>) {
const date = new Date(); const date = new Date();
@ -75,13 +79,24 @@ export default new (class DashboardPage extends StatefulPage<State, typeof actio
</tbody> </tbody>
</table> </table>
{ {ctx.headers["just-data"]
/* HTML */ `<script> ? ""
setInterval(function () { : /* HTML */ `<script>
document.location = document.location; function refresh() {
}, 15 * 1000); let xhr = new XMLHttpRequest();
</script>` 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> </div>
); );
} }

Loading…
Cancel
Save