From 131f34648d8b8fa8388f619c144480e06f5f9921 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 19 Feb 2021 15:03:48 +0300 Subject: render headline labels on the client --- js/Article.js | 6 ++++++ js/Headlines.js | 15 ++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'js') diff --git a/js/Article.js b/js/Article.js index 339d26266..4cd4d3237 100644 --- a/js/Article.js +++ b/js/Article.js @@ -130,6 +130,12 @@ const Article = { Headlines.toggleUnread(id, 0); }, + renderLabels: function(id, labels) { + return `${labels.map((label) => ` + ${App.escapeHtml(label[1])}` + ).join("")}`; + }, renderEnclosures: function (enclosures) { // enclosure list was handled by backend (HOOK_FORMAT_ENCLOSURES) diff --git a/js/Headlines.js b/js/Headlines.js index 18e0a3687..036c923a8 100755 --- a/js/Headlines.js +++ b/js/Headlines.js @@ -462,7 +462,7 @@ const Headlines = { ${hl.title} ${hl.author} - ${hl.labels} + ${Article.renderLabels(hl.id, hl.labels)} ${hl.cdm_excerpt ? hl.cdm_excerpt : ""} @@ -527,7 +527,7 @@ const Headlines = { ${hl.title} ${hl.content_preview} ${hl.author} - ${hl.labels} + ${Article.renderLabels(hl.id, hl.labels)} @@ -1240,11 +1240,16 @@ const Headlines = { } } }, + // TODO: maybe this should cause article to be rendered again, although it might cause flicker etc onLabelsUpdated: function (data) { if (data) { - data['info-for-headlines'].forEach(function (elem) { - App.findAll(".HLLCTR-" + elem.id).forEach(function (ctr) { - ctr.innerHTML = elem.labels; + data["labels-for"].forEach((row) => { + if (this.headlines[row.id]) { + this.headlines[row.id].labels = row.labels; + } + + App.findAll(`span[data-labels-for="${row.id}"]`).forEach((ctr) => { + ctr.innerHTML = Article.renderLabels(row.id, row.labels); }); }); } -- cgit v1.2.3