From d85f259cd57ad8ce2e4137f2291da855a63fd53d Mon Sep 17 00:00:00 2001 From: Benjamin Auder Date: Tue, 24 Mar 2020 16:09:28 +0100 Subject: [PATCH] Add basic news navigation with prev/next buttons --- client/src/translations/en.js | 4 +++- client/src/translations/es.js | 4 +++- client/src/translations/fr.js | 4 +++- client/src/views/News.vue | 9 ++++++++- client/src/views/Problems.vue | 2 +- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/client/src/translations/en.js b/client/src/translations/en.js index 513922a4..75d9b89e 100644 --- a/client/src/translations/en.js +++ b/client/src/translations/en.js @@ -77,6 +77,7 @@ export const translations = { "Name or Email": "Name or Email", Next_p: "Next", Next_g: "Next", + Next_n: "Next", "New connexion detected: tab now offline": "New connexion detected: tab now offline", "New correspondance game:": "New correspondance game:", "New game": "New game", @@ -100,7 +101,8 @@ export const translations = { Practice: "Practice", "Prefix?": "Prefix?", "Preset challenges": "Preset challenges", - Previous: "Previous", + Previous_n: "Previous", + Previous_p: "Previous", "Processing... Please wait": "Processing... Please wait", Problems: "Problems", "Random?": "Random?", diff --git a/client/src/translations/es.js b/client/src/translations/es.js index fb13e28e..465f39fb 100644 --- a/client/src/translations/es.js +++ b/client/src/translations/es.js @@ -77,6 +77,7 @@ export const translations = { "Name or Email": "Nombre o Email", Next_p: "Siguiente", Next_g: "Siguiente", + Next_n: "Siguiente", "New connexion detected: tab now offline": "Nueva conexión detectada: pestaña ahora desconectada", "New correspondance game:": "Nueva partida por correspondencia:", "New game": "Nueva partida", @@ -100,7 +101,8 @@ export const translations = { Practice: "Práctica", "Prefix?": "¿Prefijo?", "Preset challenges": "Desafíos registrados", - Previous: "Anterior", + Previous_p: "Anterior", + Previous_n: "Anterior", "Processing... Please wait": "Procesando... por favor espere", Problems: "Problemas", "Random?": "Aleatorio?", diff --git a/client/src/translations/fr.js b/client/src/translations/fr.js index 8524dcb6..62dd3ba0 100644 --- a/client/src/translations/fr.js +++ b/client/src/translations/fr.js @@ -77,6 +77,7 @@ export const translations = { "Name or Email": "Nom ou Email", Next_p: "Suivant", Next_g: "Suivante", + Next_n: "Suivante", "New connexion detected: tab now offline": "Nouvelle connexion détectée : onglet désormais hors ligne", "New correspondance game:": "Nouvelle partie par corespondance :", "New game": "Nouvelle partie", @@ -100,7 +101,8 @@ export const translations = { Practice: "Pratiquer", "Prefix?": "Préfixe ?", "Preset challenges": "Défis enregistrés", - Previous: "Précédent", + Previous_p: "Précédent", + Previous_n: "Précédente", "Processing... Please wait": "Traitement en cours... Attendez SVP", Problems: "Problèmes", "Random?": "Aléatoire?", diff --git a/client/src/views/News.vue b/client/src/views/News.vue index a4ce5798..dd3c84ef 100644 --- a/client/src/views/News.vue +++ b/client/src/views/News.vue @@ -23,12 +23,15 @@ main | {{ st.tr["Write news"] }} .news( v-for="n,idx in newsList" + :id="'n' + n.id" :class="{margintop:idx>0}" ) span.ndt {{ formatDatetime(n.added) }} .dev-buttons(v-if="devs.includes(st.user.id)") button(@click="editNews(n)") {{ st.tr["Edit"] }} button(@click="deleteNews(n)") {{ st.tr["Delete"] }} + button(@click="gotoPrevNext(n, 1)") {{ st.tr["Previous_n"] }} + button(@click="gotoPrevNext(n, -1)") {{ st.tr["Next_n"] }} .news-content(v-html="parseHtml(n.content)") button#loadMoreBtn( v-if="hasMore" @@ -107,6 +110,10 @@ export default { this.curnews.content = ""; // No need for added and uid fields: never updated }, + gotoPrevNext: function(n, dir) { + document.getElementById("n" + n.id)[ + (dir < 0 ? "previous" : "next") + "ElementSibling"].scrollIntoView(); + }, showModalNews: function() { this.resetCurnews(); window.doClick("modalNews"); @@ -122,7 +129,7 @@ export default { success: (res) => { if (edit) { let n = this.newsList.find(n => n.id == this.curnews.id); - if (n) n.content = this.curnews.content; + if (!!n) n.content = this.curnews.content; } else { const newNews = { content: this.curnews.content, diff --git a/client/src/views/Problems.vue b/client/src/views/Problems.vue index f1c2d08a..1884852a 100644 --- a/client/src/views/Problems.vue +++ b/client/src/views/Problems.vue @@ -54,7 +54,7 @@ main span.uname ({{ curproblem.uname }}) button.marginleft(@click="backToList()") {{ st.tr["Back to list"] }} button.nomargin(@click="gotoPrevNext($event,curproblem,1)") - | {{ st.tr["Previous"] }} + | {{ st.tr["Previous_p"] }} button.nomargin(@click="gotoPrevNext($event,curproblem,-1)") | {{ st.tr["Next_p"] }} p.oneInstructions.clickable( -- 2.44.0