|
|
|
@ -160,51 +160,50 @@ const Proiezione = () => { |
|
|
|
|
|
|
|
|
|
|
|
messagesRef.on("child_added", function (snapshot) { |
|
|
|
messagesRef.on("child_added", function (snapshot) { |
|
|
|
var messaggio = snapshot.val(); |
|
|
|
var messaggio = snapshot.val(); |
|
|
|
|
|
|
|
if (messaggio.approvato) { |
|
|
|
cambiaMessaggi((oldArray) => |
|
|
|
cambiaMessaggi((oldArray) => |
|
|
|
[...oldArray, messaggio].sort((a, b) => b.timestamp - a.timestamp) |
|
|
|
[...oldArray, messaggio].sort((a, b) => b.timestamp - a.timestamp) |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
messagesRef.on("child_changed", function (snapshot) { |
|
|
|
messagesRef.on("child_changed", function (snapshot) { |
|
|
|
|
|
|
|
// console.log(indiceCorrente); Rimane alla versione iniziale!
|
|
|
|
var messaggio = snapshot.val(); |
|
|
|
var messaggio = snapshot.val(); |
|
|
|
|
|
|
|
if (messaggio.approvato) { |
|
|
|
|
|
|
|
cambiaMessaggi((oldArray) => |
|
|
|
|
|
|
|
[...oldArray, messaggio].sort((a, b) => b.timestamp - a.timestamp) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
var nuovoIndice |
|
|
|
cambiaMessaggi((oldArray) => { |
|
|
|
cambiaMessaggi((oldArray) => { |
|
|
|
var nuoviMessaggi = [...oldArray]; |
|
|
|
nuovoIndice = oldArray.findIndex((d) => d.id === messaggio.id); |
|
|
|
var nuovoIndice = oldArray.findIndex((d) => d.id === messaggio.id); |
|
|
|
oldArray.splice(nuovoIndice, 1); |
|
|
|
if (nuovoIndice != -1) { |
|
|
|
return oldArray; |
|
|
|
nuoviMessaggi[nuovoIndice] = messaggio; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return nuoviMessaggi; |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, []); |
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
const nextMessage = (i) => { |
|
|
|
const nextMessage = (i) => { |
|
|
|
if(i === indiceCorrente) return |
|
|
|
|
|
|
|
let nuovoIndice = (i + 1) % messaggi.length; |
|
|
|
let nuovoIndice = (i + 1) % messaggi.length; |
|
|
|
|
|
|
|
cambiaindiceCorrente(nuovoIndice); |
|
|
|
if (!messaggi[nuovoIndice].approvato) { |
|
|
|
}; |
|
|
|
nextMessage(nuovoIndice); |
|
|
|
const whereAmI = () => { |
|
|
|
} else { |
|
|
|
console.log(indiceCorrente); |
|
|
|
cambiaindiceCorrente(nuovoIndice) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const messaggioCorrente = messaggi[indiceCorrente]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div> |
|
|
|
<div> |
|
|
|
<MyForm /> |
|
|
|
<MyForm /> |
|
|
|
{!messaggi.filter((m) => m.approvato).length && ( |
|
|
|
{!messaggi.length && <div>nessun messaggio</div>} |
|
|
|
<div>nessun messaggio</div> |
|
|
|
{messaggi.length && ( |
|
|
|
)} |
|
|
|
|
|
|
|
{messaggi.filter((m) => m.approvato).length && ( |
|
|
|
|
|
|
|
<div> |
|
|
|
<div> |
|
|
|
<h1>{messaggioCorrente.testo}</h1> |
|
|
|
<i>{indiceCorrente}</i> |
|
|
|
<p>da {messaggioCorrente.autore}</p> |
|
|
|
<h1>{messaggi[indiceCorrente].testo}</h1> |
|
|
|
|
|
|
|
<p>da {messaggi[indiceCorrente].autore}</p> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
)} |
|
|
|
)} |
|
|
|
<Button onClick={()=>nextMessage(indiceCorrente)}>next</Button> |
|
|
|
<Button onClick={() => nextMessage(indiceCorrente)}>next</Button> |
|
|
|
|
|
|
|
|
|
|
|
<Admin /> |
|
|
|
<Admin /> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|