|
|
|
@ -1,8 +1,8 @@ |
|
|
|
import React, { useEffect, useState } from "react"; |
|
|
|
import React, { useEffect, useState } from "react"; |
|
|
|
import firebase from "firebase/app"; |
|
|
|
import firebase from "firebase/app"; |
|
|
|
import { Button, Grid } from "@mui/material"; |
|
|
|
import { Button, Grid, Stack } from "@mui/material"; |
|
|
|
import { Admin } from "./Admin"; |
|
|
|
import videoSrc from "./video.mp4"; |
|
|
|
import { MyForm } from "./MyForm"; |
|
|
|
import logoSrc from "./logo.svg"; |
|
|
|
import { useInterval } from "./Countdown"; |
|
|
|
import { useInterval } from "./Countdown"; |
|
|
|
|
|
|
|
|
|
|
|
window.debug = false; |
|
|
|
window.debug = false; |
|
|
|
@ -16,8 +16,8 @@ export const Proiezione = () => { |
|
|
|
var messagesRef = firebase.database().ref("/messaggi"); |
|
|
|
var messagesRef = firebase.database().ref("/messaggi"); |
|
|
|
|
|
|
|
|
|
|
|
messagesRef.on("child_added", function (snapshot) { |
|
|
|
messagesRef.on("child_added", function (snapshot) { |
|
|
|
|
|
|
|
console.log("child_added"); |
|
|
|
var messaggio = snapshot.val(); |
|
|
|
var messaggio = snapshot.val(); |
|
|
|
console.log(messaggio); |
|
|
|
|
|
|
|
cambiaMessaggi((oldArray) => { |
|
|
|
cambiaMessaggi((oldArray) => { |
|
|
|
const newArray = [...oldArray, messaggio].sort( |
|
|
|
const newArray = [...oldArray, messaggio].sort( |
|
|
|
(a, b) => b.timestamp - a.timestamp |
|
|
|
(a, b) => b.timestamp - a.timestamp |
|
|
|
@ -28,6 +28,7 @@ export const Proiezione = () => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
messagesRef.on("child_changed", function (snapshot) { |
|
|
|
messagesRef.on("child_changed", function (snapshot) { |
|
|
|
|
|
|
|
console.log("child_changed"); |
|
|
|
const messaggio = snapshot.val(); |
|
|
|
const messaggio = snapshot.val(); |
|
|
|
cambiaMessaggi((oldArray) => { |
|
|
|
cambiaMessaggi((oldArray) => { |
|
|
|
const newArray = [...oldArray]; |
|
|
|
const newArray = [...oldArray]; |
|
|
|
@ -46,15 +47,14 @@ export const Proiezione = () => { |
|
|
|
cambiaindiceCorrente(newIndice); |
|
|
|
cambiaindiceCorrente(newIndice); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const ContainerMessaggio = () => { |
|
|
|
const ContainerMessaggio = ({ messaggiApprovati, indiceCorrente }) => { |
|
|
|
if (!messaggiApprovati.length) { |
|
|
|
if (!messaggiApprovati.length) { |
|
|
|
return <div>nessun messaggio</div>; |
|
|
|
return <div>nessun messaggio</div>; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
const messaggioCorrente = messaggiApprovati[indiceCorrente]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<Messaggio |
|
|
|
<Messaggio |
|
|
|
messaggioCorrente={messaggioCorrente} |
|
|
|
messaggiApprovati={messaggiApprovati} |
|
|
|
|
|
|
|
indiceCorrente={indiceCorrente} |
|
|
|
nextMessage={nextMessage} |
|
|
|
nextMessage={nextMessage} |
|
|
|
/> |
|
|
|
/> |
|
|
|
); |
|
|
|
); |
|
|
|
@ -63,23 +63,20 @@ export const Proiezione = () => { |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div> |
|
|
|
<div> |
|
|
|
<Grid |
|
|
|
<VideoComponent /> |
|
|
|
|
|
|
|
<ContainerMessaggio |
|
|
|
|
|
|
|
messaggiApprovati={messaggiApprovati} |
|
|
|
|
|
|
|
indiceCorrente={indiceCorrente} |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
<img |
|
|
|
|
|
|
|
src={logoSrc} |
|
|
|
style={{ |
|
|
|
style={{ |
|
|
|
width: "100%", |
|
|
|
width: 120, |
|
|
|
height: "100vh", |
|
|
|
position: "absolute", |
|
|
|
background: "black", |
|
|
|
top: 20, |
|
|
|
fontFamily: "sans-serif", |
|
|
|
right: 20, |
|
|
|
fontWeight: "bold", |
|
|
|
|
|
|
|
color: "white", |
|
|
|
|
|
|
|
display: "flex", |
|
|
|
|
|
|
|
justifyContent: "space-around", |
|
|
|
|
|
|
|
alignContent: "center", |
|
|
|
|
|
|
|
alignItems: "center", |
|
|
|
|
|
|
|
textAlign: "center", |
|
|
|
|
|
|
|
}} |
|
|
|
}} |
|
|
|
> |
|
|
|
/> |
|
|
|
<ContainerMessaggio /> |
|
|
|
|
|
|
|
</Grid> |
|
|
|
|
|
|
|
</div> |
|
|
|
</div> |
|
|
|
); |
|
|
|
); |
|
|
|
}; |
|
|
|
}; |
|
|
|
@ -97,24 +94,73 @@ const Immagine = ({ url }) => { |
|
|
|
></div> |
|
|
|
></div> |
|
|
|
); |
|
|
|
); |
|
|
|
}; |
|
|
|
}; |
|
|
|
const Messaggio = ({ nextMessage, messaggioCorrente }) => { |
|
|
|
|
|
|
|
const [timeLeft, setTimeLeft] = useState(5); |
|
|
|
const Messaggio = ({ nextMessage, messaggiApprovati, indiceCorrente }) => { |
|
|
|
|
|
|
|
const [timeLeft, setTimeLeft] = useState(6); |
|
|
|
|
|
|
|
const [fadeProp, setFadeProp] = useState("in"); |
|
|
|
|
|
|
|
const [messaggioDaMostrare, setMessaggioDaMostrare] = useState(null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
if (messaggiApprovati[indiceCorrente] != messaggioDaMostrare) { |
|
|
|
|
|
|
|
setFadeProp("out"); |
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
|
|
setMessaggioDaMostrare(messaggiApprovati[indiceCorrente]); |
|
|
|
|
|
|
|
setFadeProp("in"); |
|
|
|
|
|
|
|
}, 1000); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, [messaggiApprovati, indiceCorrente]); |
|
|
|
|
|
|
|
|
|
|
|
useInterval(() => { |
|
|
|
useInterval(() => { |
|
|
|
if (timeLeft === 1) { |
|
|
|
if (timeLeft === 1) { |
|
|
|
|
|
|
|
setFadeProp("out"); |
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
nextMessage(); |
|
|
|
nextMessage(); |
|
|
|
|
|
|
|
}, 2000); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
setTimeLeft(timeLeft - 1); |
|
|
|
setTimeLeft(timeLeft - 1); |
|
|
|
} |
|
|
|
} |
|
|
|
}, 1000); |
|
|
|
}, 1000); |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
|
|
|
|
<div className={"fade-" + fadeProp}> |
|
|
|
|
|
|
|
<div |
|
|
|
|
|
|
|
style={{ |
|
|
|
|
|
|
|
position: "absolute", |
|
|
|
|
|
|
|
fontFamily: "Lineatura", |
|
|
|
|
|
|
|
width: "100%", |
|
|
|
|
|
|
|
height: "100vh", |
|
|
|
|
|
|
|
fontWeight: "bold", |
|
|
|
|
|
|
|
color: "white", |
|
|
|
|
|
|
|
display: "flex", |
|
|
|
|
|
|
|
justifyContent: "space-around", |
|
|
|
|
|
|
|
alignContent: "center", |
|
|
|
|
|
|
|
alignItems: "center", |
|
|
|
|
|
|
|
textAlign: "center", |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
{messaggioDaMostrare && ( |
|
|
|
<div> |
|
|
|
<div> |
|
|
|
{messaggioCorrente.immagineURL && ( |
|
|
|
{messaggioDaMostrare.immagineURL && ( |
|
|
|
<Immagine url={messaggioCorrente.immagineURL} /> |
|
|
|
<Immagine url={messaggioDaMostrare.immagineURL} /> |
|
|
|
)} |
|
|
|
)} |
|
|
|
<h1>{messaggioCorrente.testo}</h1> |
|
|
|
<h1 |
|
|
|
<p>da {messaggioCorrente.autore}</p> |
|
|
|
style={{ |
|
|
|
|
|
|
|
textShadow: |
|
|
|
|
|
|
|
"0px 0px 10px rgba(0,0,0,100), 0px 0px 10px rgba(0,0,0,100), 0px 0px 10px rgba(0,0,0,100)", |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
{messaggioDaMostrare.testo} |
|
|
|
|
|
|
|
</h1> |
|
|
|
|
|
|
|
<p |
|
|
|
|
|
|
|
style={{ |
|
|
|
|
|
|
|
display: "inline-block", |
|
|
|
|
|
|
|
background: "black", |
|
|
|
|
|
|
|
padding: "0px 6px", |
|
|
|
|
|
|
|
paddingBottom: "4px", |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
da {messaggioDaMostrare.autore} |
|
|
|
|
|
|
|
</p> |
|
|
|
|
|
|
|
|
|
|
|
{debug && ( |
|
|
|
{debug && ( |
|
|
|
<div> |
|
|
|
<div> |
|
|
|
@ -123,5 +169,16 @@ const Messaggio = ({ nextMessage, messaggioCorrente }) => { |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
)} |
|
|
|
)} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
)} |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
</div> |
|
|
|
); |
|
|
|
); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const VideoComponent = React.memo(() => { |
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
|
|
<video autoPlay muted loop id="myVideo"> |
|
|
|
|
|
|
|
<source src={videoSrc} type="video/mp4" /> |
|
|
|
|
|
|
|
</video> |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}); |
|
|
|
|