From 591e03b1894bf0d4f4ce26de3fc73ee6cc11ee80 Mon Sep 17 00:00:00 2001 From: enne2 Date: Sat, 24 Dec 2022 17:23:11 +0100 Subject: [PATCH] =?UTF-8?q?=C3=A8=20una=20vita=20difficile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 57 ++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/src/index.js b/src/index.js index 116b057..0037127 100644 --- a/src/index.js +++ b/src/index.js @@ -160,51 +160,50 @@ const Proiezione = () => { messagesRef.on("child_added", function (snapshot) { var messaggio = snapshot.val(); - cambiaMessaggi((oldArray) => - [...oldArray, messaggio].sort((a, b) => b.timestamp - a.timestamp) - ); + if (messaggio.approvato) { + cambiaMessaggi((oldArray) => + [...oldArray, messaggio].sort((a, b) => b.timestamp - a.timestamp) + ); + } }); messagesRef.on("child_changed", function (snapshot) { + // console.log(indiceCorrente); Rimane alla versione iniziale! var messaggio = snapshot.val(); - - cambiaMessaggi((oldArray) => { - var nuoviMessaggi = [...oldArray]; - var nuovoIndice = oldArray.findIndex((d) => d.id === messaggio.id); - if (nuovoIndice != -1) { - nuoviMessaggi[nuovoIndice] = messaggio; - } - return nuoviMessaggi; - }); + if (messaggio.approvato) { + cambiaMessaggi((oldArray) => + [...oldArray, messaggio].sort((a, b) => b.timestamp - a.timestamp) + ); + } else { + var nuovoIndice + cambiaMessaggi((oldArray) => { + nuovoIndice = oldArray.findIndex((d) => d.id === messaggio.id); + oldArray.splice(nuovoIndice, 1); + return oldArray; + }); + } }); }, []); const nextMessage = (i) => { - if(i === indiceCorrente) return let nuovoIndice = (i + 1) % messaggi.length; - - if (!messaggi[nuovoIndice].approvato) { - nextMessage(nuovoIndice); - } else { - cambiaindiceCorrente(nuovoIndice) - } + cambiaindiceCorrente(nuovoIndice); + }; + const whereAmI = () => { + console.log(indiceCorrente); }; - - const messaggioCorrente = messaggi[indiceCorrente]; - return (
- {!messaggi.filter((m) => m.approvato).length && ( -
nessun messaggio
- )} - {messaggi.filter((m) => m.approvato).length && ( + {!messaggi.length &&
nessun messaggio
} + {messaggi.length && (
-

{messaggioCorrente.testo}

-

da {messaggioCorrente.autore}

+ {indiceCorrente} +

{messaggi[indiceCorrente].testo}

+

da {messaggi[indiceCorrente].autore}

)} - +