From c2ac3fc7532f17a7f5f7acd4f5c95a0c1d8a8d96 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ji=C5=99=C3=AD=20Setni=C4=8Dka?= <setnicka@seznam.cz>
Date: Thu, 25 Mar 2021 12:35:56 +0100
Subject: [PATCH] =?UTF-8?q?Fix=20informov=C3=A1n=C3=AD=20o=20nov=C3=BDch?=
 =?UTF-8?q?=20novink=C3=A1ch?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Pokud byla vypsaná zpráva o žádných novinkách, tak se započítala jako novinka,
při dalším reloadu se vyměnil celý obsah <div> a tak se lišil počet.

Teď už se zpráva o žádných novinkách při reloadu nezmizí.
---
 mo/web/templates/parts/messages.html    |  3 ---
 mo/web/templates/parts/user_news.html   |  7 ++++++-
 mo/web/templates/user_contest.html      |  2 +-
 mo/web/templates/user_contest_task.html |  2 +-
 static/js/news-reloader.js              | 11 ++++++++++-
 5 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/mo/web/templates/parts/messages.html b/mo/web/templates/parts/messages.html
index 93663223..d90436f4 100644
--- a/mo/web/templates/parts/messages.html
+++ b/mo/web/templates/parts/messages.html
@@ -12,6 +12,3 @@
 	{% endif %}
 </div>
 {% endfor %}
-{% if not messages %}
-<p><em>Žádné novinky zatím nebyly vydány.</em>
-{% endif %}
diff --git a/mo/web/templates/parts/user_news.html b/mo/web/templates/parts/user_news.html
index b873d205..3748a6ab 100644
--- a/mo/web/templates/parts/user_news.html
+++ b/mo/web/templates/parts/user_news.html
@@ -1,6 +1,11 @@
 <div id="novinky">
 {% include "parts/messages.html" %}
 </div>
+<div id="novinky-status">
+{% if not messages %}
+<p><em>Žádné novinky zatím nebyly vydány.</em>
+{% endif %}
+</div>
 <script type="text/javascript">
-r = new NewsReloader(document.getElementById("novinky"), "{{ url }}", 60000);
+r = new NewsReloader(document.getElementById("novinky"), document.getElementById("novinky-status"), "{{ url }}", 60000);
 </script>
diff --git a/mo/web/templates/user_contest.html b/mo/web/templates/user_contest.html
index c676c073..f4bf8c8c 100644
--- a/mo/web/templates/user_contest.html
+++ b/mo/web/templates/user_contest.html
@@ -107,7 +107,7 @@
 
 {% if contest.round.has_messages %}
 <h3>Novinky k soutěži</h3>
-{% with title="Novinky k soutěži", url=url_for('user_contest_news', id=contest.contest_id) %}
+{% with url=url_for('user_contest_news', id=contest.contest_id) %}
 	{% include "parts/user_news.html" %}
 {% endwith %}
 {% endif %}
diff --git a/mo/web/templates/user_contest_task.html b/mo/web/templates/user_contest_task.html
index 01c3263b..32308295 100644
--- a/mo/web/templates/user_contest_task.html
+++ b/mo/web/templates/user_contest_task.html
@@ -93,7 +93,7 @@
 
 {% if contest.round.has_messages %}
 <h3>Novinky k soutěži</h3>
-{% with title="Novinky k soutěži", url=url_for('user_contest_news', id=contest.contest_id) %}
+{% with url=url_for('user_contest_news', id=contest.contest_id) %}
 	{% include "parts/user_news.html" %}
 {% endwith %}
 {% endif %}
diff --git a/static/js/news-reloader.js b/static/js/news-reloader.js
index 04fe721d..0d5c518d 100644
--- a/static/js/news-reloader.js
+++ b/static/js/news-reloader.js
@@ -3,8 +3,9 @@ class NewsReloader {
 	notification_interval = null;
 	original_title = "";
 
-	constructor(element, url, check_interval=60000) {
+	constructor(element, status_element, url, check_interval=60000) {
 		this.element = element;
+		this.status_element = status_element;
 		this.url = url;
 		this.check_interval = check_interval;
 
@@ -44,6 +45,14 @@ class NewsReloader {
 				var newsArr = JSON.parse(this.responseText);
 				var count = newsArr.length
 
+				if (t.status_element != null) {
+					if (count == 0) {
+						t.status_element.innerHTML = "<p><em>Žádné novinky zatím nebyly vydány.</em>";
+					} else {
+						t.status_element.innerHTML = "";
+					}
+				}
+
 				var markN = 0; // how many elements to mark with class "new"
 				if (count > t.news_count) {
 					markN = count - t.news_count;
-- 
GitLab