|
|
|
@ -2,6 +2,7 @@ import React, { useEffect, useState } from "react"; |
|
|
|
import firebase from "firebase/app"; |
|
|
|
import firebase from "firebase/app"; |
|
|
|
import { Button } from "@mui/material"; |
|
|
|
import { Button } from "@mui/material"; |
|
|
|
import { MyForm, Admin } from "./index"; |
|
|
|
import { MyForm, Admin } from "./index"; |
|
|
|
|
|
|
|
import { useInterval } from "./Countdown"; |
|
|
|
|
|
|
|
|
|
|
|
export const Proiezione = () => { |
|
|
|
export const Proiezione = () => { |
|
|
|
const [messaggi, cambiaMessaggi] = useState([]); |
|
|
|
const [messaggi, cambiaMessaggi] = useState([]); |
|
|
|
@ -23,7 +24,6 @@ export const Proiezione = () => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
messagesRef.on("child_changed", function (snapshot) { |
|
|
|
messagesRef.on("child_changed", function (snapshot) { |
|
|
|
// console.log(indiceCorrente); Rimane alla versione iniziale!
|
|
|
|
|
|
|
|
const messaggio = snapshot.val(); |
|
|
|
const messaggio = snapshot.val(); |
|
|
|
cambiaMessaggi((oldArray) => { |
|
|
|
cambiaMessaggi((oldArray) => { |
|
|
|
const newArray = [...oldArray]; |
|
|
|
const newArray = [...oldArray]; |
|
|
|
@ -42,23 +42,49 @@ export const Proiezione = () => { |
|
|
|
cambiaindiceCorrente(newIndice); |
|
|
|
cambiaindiceCorrente(newIndice); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const Messaggio = () => { |
|
|
|
const ContainerMessaggio = () => { |
|
|
|
if (!messaggiApprovati.length) return <div>nessun messaggio</div>; |
|
|
|
if (!messaggiApprovati.length) { |
|
|
|
|
|
|
|
<div>nessun messaggio</div>; |
|
|
|
|
|
|
|
} else { |
|
|
|
const messaggioCorrente = messaggiApprovati[indiceCorrente]; |
|
|
|
const messaggioCorrente = messaggiApprovati[indiceCorrente]; |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div> |
|
|
|
<Messaggio |
|
|
|
<h1>{messaggioCorrente.testo}</h1> |
|
|
|
messaggioCorrente={messaggioCorrente} |
|
|
|
<p>da {messaggioCorrente.autore}</p> |
|
|
|
nextMessage={nextMessage} |
|
|
|
<Button onClick={() => nextMessage()}>next</Button> |
|
|
|
/> |
|
|
|
</div> |
|
|
|
|
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div> |
|
|
|
<div> |
|
|
|
<MyForm /> |
|
|
|
<MyForm /> |
|
|
|
<Messaggio></Messaggio> |
|
|
|
<ContainerMessaggio /> |
|
|
|
<Admin /> |
|
|
|
<Admin /> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
); |
|
|
|
); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const Messaggio = ({ nextMessage, messaggioCorrente }) => { |
|
|
|
|
|
|
|
const [timeLeft, setTimeLeft] = useState(5); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Decrement the timer by 1 second every 1000ms
|
|
|
|
|
|
|
|
useInterval(() => { |
|
|
|
|
|
|
|
if (timeLeft === 1) { |
|
|
|
|
|
|
|
nextMessage(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
setTimeLeft(timeLeft - 1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, 1000); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log("asdf"); |
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
|
|
<div> |
|
|
|
|
|
|
|
<h1>{messaggioCorrente.testo}</h1> |
|
|
|
|
|
|
|
<p>da {messaggioCorrente.autore}</p> |
|
|
|
|
|
|
|
<Button onClick={() => nextMessage()}>next</Button> |
|
|
|
|
|
|
|
{timeLeft} |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}; |
|
|
|
|