|
|
|
@ -70,7 +70,7 @@ const Messaggio = ({ messaggiApprovati }) => { |
|
|
|
const [fadeProp, setFadeProp] = useState("in"); |
|
|
|
const [fadeProp, setFadeProp] = useState("in"); |
|
|
|
const [messaggioDaMostrare, setMessaggioDaMostrare] = useState(null); |
|
|
|
const [messaggioDaMostrare, setMessaggioDaMostrare] = useState(null); |
|
|
|
const [indiceCorrente, cambiaindiceCorrente] = useState(0); |
|
|
|
const [indiceCorrente, cambiaindiceCorrente] = useState(0); |
|
|
|
|
|
|
|
const [imageWidth, setImageWidth] = useState(0); |
|
|
|
const nextMessage = () => { |
|
|
|
const nextMessage = () => { |
|
|
|
const newIndice = (indiceCorrente + 1) % messaggiApprovati.length; |
|
|
|
const newIndice = (indiceCorrente + 1) % messaggiApprovati.length; |
|
|
|
console.log("newIndice", newIndice); |
|
|
|
console.log("newIndice", newIndice); |
|
|
|
@ -93,8 +93,10 @@ const Messaggio = ({ messaggiApprovati }) => { |
|
|
|
const timeout = setTimeout(() => { |
|
|
|
const timeout = setTimeout(() => { |
|
|
|
if (newMessage.immagineURL) { |
|
|
|
if (newMessage.immagineURL) { |
|
|
|
const img = new Image(); |
|
|
|
const img = new Image(); |
|
|
|
img.onload = (img) => { |
|
|
|
img.onload = (i) => { |
|
|
|
console.log("loaded"); |
|
|
|
console.log("loaded"); |
|
|
|
|
|
|
|
console.log(img.width, img.height); |
|
|
|
|
|
|
|
setImageWidth(img.width > img.height ? 600 : 200); |
|
|
|
showNextMessage(newMessage); |
|
|
|
showNextMessage(newMessage); |
|
|
|
}; |
|
|
|
}; |
|
|
|
img.src = newMessage.immagineURL; |
|
|
|
img.src = newMessage.immagineURL; |
|
|
|
@ -106,7 +108,7 @@ const Messaggio = ({ messaggiApprovati }) => { |
|
|
|
} |
|
|
|
} |
|
|
|
}, [indiceCorrente]); |
|
|
|
}, [indiceCorrente]); |
|
|
|
|
|
|
|
|
|
|
|
console.log(messaggioDaMostrare); |
|
|
|
console.log(imageWidth); |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div className={"fade-" + fadeProp}> |
|
|
|
<div className={"fade-" + fadeProp}> |
|
|
|
<div |
|
|
|
<div |
|
|
|
@ -130,7 +132,7 @@ const Messaggio = ({ messaggiApprovati }) => { |
|
|
|
<img |
|
|
|
<img |
|
|
|
src={messaggioDaMostrare.immagineURL} |
|
|
|
src={messaggioDaMostrare.immagineURL} |
|
|
|
style={{ |
|
|
|
style={{ |
|
|
|
width: 200, |
|
|
|
width: imageWidth, |
|
|
|
}} |
|
|
|
}} |
|
|
|
/> |
|
|
|
/> |
|
|
|
)} |
|
|
|
)} |
|
|
|
|