From 778a807c3efb43636a638e05460ec5fb00228c76 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Sun, 21 Feb 2021 15:03:27 -0500 Subject: [PATCH 1/7] Send out a comment message immediately to trigger onopen --- grip/app.py | 1 + 1 file changed, 1 insertion(+) diff --git a/grip/app.py b/grip/app.py index 123d00f..6bfe8bc 100644 --- a/grip/app.py +++ b/grip/app.py @@ -229,6 +229,7 @@ def _render_refresh(self, subpath=None): def gen(): last_updated = self.reader.last_updated(subpath) + yield ': started\r\n\r\n' try: while not shutdown_event.is_set(): time.sleep(0.3) From e03901efe96ee8723dee501f957536fee78ae6a0 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Sun, 21 Feb 2021 15:04:18 -0500 Subject: [PATCH 2/7] Cleaner display of non-user content markdown --- grip/templates/index.html | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/grip/templates/index.html b/grip/templates/index.html index 10970f0..aee13ef 100644 --- a/grip/templates/index.html +++ b/grip/templates/index.html @@ -20,6 +20,11 @@ margin-top: 64px; margin-bottom: 21px; } + #grip-readme-header { + position: relative; + top: -1em; + color: #666; + } /* User-content tweaks */ .timeline-comment-wrapper > .timeline-comment:after, .timeline-comment-wrapper > .timeline-comment:before { @@ -108,20 +113,17 @@ {% if not user_content %} -
- {% if title or filename %} -
-

- - {{ title or filename }} -

-
- {% endif %} -
-
- {{ content|safe }} -
-
+ {% if title or filename %} +

+ + {{ title or filename }} +

+ {% endif %} + +
+
+ {{ content|safe }} +
{% else %} From 6dfe921716774a252317a0b3c5a0b64a238c1639 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Sun, 21 Feb 2021 15:04:27 -0500 Subject: [PATCH 3/7] Fix onerror --- grip/templates/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grip/templates/index.html b/grip/templates/index.html index aee13ef..16d01e3 100644 --- a/grip/templates/index.html +++ b/grip/templates/index.html @@ -81,7 +81,7 @@ } source.onerror = function(e) { - if (e.readyState === EventSource.CLOSED && isRendering) { + if (isRendering) { isRendering = false; document.title = initialTitle; } From 40d3380deb5fda3c9ed5907de433516c78e83b74 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Sun, 21 Feb 2021 15:11:00 -0500 Subject: [PATCH 4/7] Fix comment rendering --- grip/templates/index.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/grip/templates/index.html b/grip/templates/index.html index 16d01e3..133c815 100644 --- a/grip/templates/index.html +++ b/grip/templates/index.html @@ -26,10 +26,16 @@ color: #666; } /* User-content tweaks */ + .timeline-comment-wrapper { + padding-left: 0; + } .timeline-comment-wrapper > .timeline-comment:after, .timeline-comment-wrapper > .timeline-comment:before { content: none; } + .discussion-timeline { + float: none; + } /* User-content overrides */ .discussion-timeline.wide { width: 920px; From b2c72b00b3161ec8eb8ae2ca227d41d8d70fdfae Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Sun, 21 Feb 2021 15:11:22 -0500 Subject: [PATCH 5/7] Add a status indicator --- grip/templates/index.html | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/grip/templates/index.html b/grip/templates/index.html index 133c815..fc6631a 100644 --- a/grip/templates/index.html +++ b/grip/templates/index.html @@ -25,6 +25,38 @@ top: -1em; color: #666; } + #grip-status-indicator.grip-floating-indicator { + position: relative; + top: calc(0.75em + 15px); + right: 15px; + color: #666; + } + #grip-status-indicator { + float: right; + text-transform: uppercase; + cursor: default; + -webkit-user-select: none; + user-select: none; + font-weight: bold; + --yellow: #FFDC00; + --red: #FF4136; + --green: #2ECC40; + } + #grip-status-indicator::after { + content: ""; + display: inline-block; + width: 0.85em; + height: 0.85em; + background: var(--color); + border-radius: 50%; + vertical-align: middle; + position: relative; + bottom: 1.5px; + margin-left: 0.5em; + } + #grip-status-indicator + #grip-content > :first-child { + margin-top: 0; + } /* User-content tweaks */ .timeline-comment-wrapper { padding-left: 0; @@ -73,13 +105,27 @@ var source = new EventSource(eventSourceUrl); var isRendering = false; + var statusElement = document.getElementById('grip-status-indicator'); + statusElement.hidden = false; + statusElement.textContent = 'Connecting'; + statusElement.style.setProperty('--color', 'var(--yellow)'); + + source.onopen = function() { + statusElement.textContent = 'Connected'; + statusElement.style.setProperty('--color', 'var(--green)'); + } + source.onmessage = function(ev) { var msg = JSON.parse(ev.data); if (msg.updating) { isRendering = true; + statusElement.textContent = 'Updating'; + statusElement.style.setProperty('--color', 'var(--yellow)'); document.title = '(Rendering) ' + document.title; } else { isRendering = false; + statusElement.textContent = 'Connected'; + statusElement.style.setProperty('--color', 'var(--green)'); document.title = initialTitle; contentElement.innerHTML = msg.content; showCanonicalImages(); @@ -91,6 +137,8 @@ isRendering = false; document.title = initialTitle; } + statusElement.textContent = 'Disconnected'; + statusElement.style.setProperty('--color', 'var(--red)'); } } @@ -123,6 +171,7 @@

{{ title or filename }} +

{% endif %} @@ -146,10 +195,14 @@

+

{% endif %}
+ {% if not title %} + + {% endif %}
{{ content|safe }}
From bf00c21dc900268189d3ceeb3b8dfc756696d6c6 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Sun, 21 Feb 2021 15:14:06 -0500 Subject: [PATCH 6/7] Tweak layout --- grip/templates/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grip/templates/index.html b/grip/templates/index.html index fc6631a..198906e 100644 --- a/grip/templates/index.html +++ b/grip/templates/index.html @@ -28,7 +28,7 @@ #grip-status-indicator.grip-floating-indicator { position: relative; top: calc(0.75em + 15px); - right: 15px; + right: calc(0.5em + 15px); color: #666; } #grip-status-indicator { From 69e7ddb8f21a954b3214b646f0c4deed354c1df5 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Sun, 21 Feb 2021 15:17:09 -0500 Subject: [PATCH 7/7] Adjust spacing --- grip/templates/index.html | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/grip/templates/index.html b/grip/templates/index.html index 198906e..f0eb7e7 100644 --- a/grip/templates/index.html +++ b/grip/templates/index.html @@ -26,9 +26,7 @@ color: #666; } #grip-status-indicator.grip-floating-indicator { - position: relative; - top: calc(0.75em + 15px); - right: calc(0.5em + 15px); + margin: calc(0.5em + 15px); color: #666; } #grip-status-indicator {