From 1e3650bf92c26f3496c94c778ba6c597313ee891 Mon Sep 17 00:00:00 2001 From: Danilo Di Cuia Date: Mon, 3 Apr 2023 14:43:32 +0200 Subject: [PATCH] aggiunto indice --- src/Galleria.js | 93 +++++++++++++++++++++++----------------------- src/ImageUpload.js | 2 +- src/MyForm.js | 9 +++-- src/index.js | 64 +++++++++++++++++++++++++++++-- 4 files changed, 114 insertions(+), 54 deletions(-) diff --git a/src/Galleria.js b/src/Galleria.js index 9fa8a15..99bc8d9 100644 --- a/src/Galleria.js +++ b/src/Galleria.js @@ -35,70 +35,69 @@ export const Galleria = () => { messaggi .filter((d) => d.immagineURL != null) .map((d) => { - console.log(d.immagineURL); return d.immagineURL; }) ); }); }, [evento]); - useEffect(() => { - if (images) { - function loadImage() { - const img = new Image(); - img.src = images[imgIndex]; - img.onload = () => { - if (imgIndex < images.length) { - cambiaimgIndex((i) => { - return i + 1; - }); - } - }; - } - loadImage(); - } - }, [imgIndex, images]); + // useEffect(() => { + // if (images) { + // function loadImage() { + // const img = new Image(); + // img.src = images[imgIndex]; + // img.onload = () => { + // if (imgIndex < images.length) { + // cambiaimgIndex((i) => { + // return i + 1; + // }); + // } + // }; + // } + // loadImage(); + // } + // }, [imgIndex, images]); return (
- {imgIndex !== images.length && ( + {/* {imgIndex !== images.length && ( )} - {imgIndex === images.length && ( -
+ + + + - - - - -
- )} + /> +
+ {/* )} */} ); }; diff --git a/src/ImageUpload.js b/src/ImageUpload.js index 3539c75..2c25696 100644 --- a/src/ImageUpload.js +++ b/src/ImageUpload.js @@ -1,6 +1,6 @@ import React, { useState } from "react"; import firebase from "firebase/compat/app"; -import "firebase/storage"; +import "firebase/compat/storage"; import { Stack } from "@mui/system"; import { Button } from "@mui/material"; diff --git a/src/MyForm.js b/src/MyForm.js index ad74e2b..a2de7c1 100644 --- a/src/MyForm.js +++ b/src/MyForm.js @@ -14,8 +14,11 @@ export const MyForm = () => { const [mandato, setMandato] = useState(false); const [imageUploading, setImageUploading] = useState(false); const [immagineURL, cambiaimmagineURL] = useState(null); - const { register, handleSubmit } = useForm(); - const onSubmit = ({ testo, autore }) => { + const { register, handleSubmit, reset } = useForm(); + const onSubmit = ({ testo, autore }, e) => { + reset("", { + keepValues: false, + }); setMandato(true); var postListRef = firebase.database().ref(`messaggi/${evento}`); var newPostRef = postListRef.push(); @@ -54,7 +57,7 @@ export const MyForm = () => {

puoi rimandere un altro messaggio in... - setMandato(false)} duration={10} /> + setMandato(false)} duration={5} />

); diff --git a/src/index.js b/src/index.js index 86a612f..e869191 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ import "./App.css"; -import React from "react"; +import React, { useEffect, useState } from "react"; import ReactDOM from "react-dom/client"; -import { BrowserRouter as Router, Routes, Route } from "react-router-dom"; +import { BrowserRouter as Router, Routes, Route, Link } from "react-router-dom"; import firebase from "firebase/compat/app"; import "firebase/compat/database"; import "firebase/compat/analytics"; @@ -9,6 +9,14 @@ import { Proiezione } from "./Proiezione"; import { MyForm } from "./MyForm"; import { Admin } from "./Admin"; import { Galleria } from "./Galleria"; +import { Stack } from "@mui/system"; +import { Container, Typography } from "@mui/material"; +import List from "@mui/material/List"; +import ListItem from "@mui/material/ListItem"; +import ListItemText from "@mui/material/ListItemText"; +import ListItemAvatar from "@mui/material/ListItemAvatar"; +import Avatar from "@mui/material/Avatar"; +import BeachAccessIcon from "@mui/icons-material/BeachAccess"; const firebaseConfig = { apiKey: "AIzaSyBWE1l8WV_7eyKT-PMu0Kq2w_WiV0SUhJw", @@ -25,10 +33,60 @@ const firebaseConfig = { firebase.initializeApp(firebaseConfig); firebase.analytics(); +const ListaEventi = () => { + const [eventi, cambiaEventi] = useState([]); + + useEffect(() => { + var messagesRef = firebase.database().ref(`/eventi`); + + messagesRef.once("value", function (snapshot) { + const eventiObject = snapshot.val(); + const e = Object.keys(eventiObject).map((d) => { + console.log(eventiObject[d]); + return ( + + {/* + + + + */} + + + + + ); + }); + cambiaEventi(e); + }); + }, []); + + if (!eventi) return
; + return ( + + + + + I nostri eventi + + + + {eventi} + + + ); +}; + ReactDOM.createRoot(document.getElementById("root")).render( - } /> + } /> } /> } /> } />