From 9689f2daa6c34e7d24d5cf1648168c66c5678385 Mon Sep 17 00:00:00 2001
From: Arjun Satarkar
Date: Sun, 30 Jul 2023 18:17:35 +0530
Subject: Add auto-refresh checkbox, don't auto-refresh except on front page
Also use input type "hidden" instead of display: none where appropriate
(no observable effects, just cleaner).
---
static/scripts/auto_refresh.js | 24 ++++++++++++++++++++++++
views/index.tpl | 23 +++++++++++++++--------
2 files changed, 39 insertions(+), 8 deletions(-)
diff --git a/static/scripts/auto_refresh.js b/static/scripts/auto_refresh.js
index 20fc5c6..48af816 100644
--- a/static/scripts/auto_refresh.js
+++ b/static/scripts/auto_refresh.js
@@ -1,6 +1,28 @@
(() => {
+ const onFrontPage = () => {
+ const searchParams = new URLSearchParams(window.location.search);
+ let pageNum = searchParams.get("page_num");
+ return (pageNum === "1") || (pageNum === null);
+ };
+
+ const refreshCheckboxLabel = document.querySelector("label#refresh_checkbox_label");
+ if (onFrontPage()) {
+ refreshCheckboxLabel.setAttribute("style", "");
+ }
+
const UPDATE_INTERVAL_MILLISECONDS = 1 * 60 * 1000; // 1 minute
setInterval(async () => {
+ if (!onFrontPage()) {
+ return;
+ }
+
+ const refreshCheckbox = document.querySelector("label#refresh_checkbox_label > input");
+ if (!refreshCheckbox.checked) {
+ return;
+ }
+
+ console.log("Refreshing entries...");
+
const response = await fetch(window.location);
if (!response.ok) {
return;
@@ -10,5 +32,7 @@
const parser = new DOMParser();
const newDoc = parser.parseFromString(responseText, "text/html");
document.querySelector("table").innerHTML = newDoc.querySelector("table").innerHTML;
+
+ console.log("Refreshed entries.");
}, UPDATE_INTERVAL_MILLISECONDS);
})();
diff --git a/views/index.tpl b/views/index.tpl
index b00b7d0..67eb413 100644
--- a/views/index.tpl
+++ b/views/index.tpl
@@ -41,6 +41,10 @@
overflow: auto;
white-space: nowrap;
}
+
+ label#refresh_checkbox_label {
+ float: right;
+ }
@@ -52,6 +56,9 @@
List feeds
+
Filter