From 43f6954f53e5361142ddd88d72ad859058dde2a9 Mon Sep 17 00:00:00 2001 From: Rei Date: Fri, 29 Dec 2023 09:33:19 +0000 Subject: [PATCH] Working code, need to fix Database formatting --- src/App.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/App.js b/src/App.js index 0cd7bac..1a46b89 100644 --- a/src/App.js +++ b/src/App.js @@ -11,6 +11,7 @@ import { getDocs, addDoc } from "firebase/firestore"; +import { onSnapshot } from "firebase/firestore"; // Import required compenets from Bootstrap and React-Boostrap import Form from 'react-bootstrap/Form'; @@ -33,6 +34,15 @@ export function MyForm(props) { const [selectedOptions, setSelectedOptions] = useState([]); const [incidents, setIncidents] = useState([]); // Declare incidents as an empty array + // Fetch incidents from Firestore when the component mounts + useEffect(() => { + const incidentsRef = collection(db, "incidents"); + getDocs(incidentsRef).then((snapshot) => { + const incidentsArray = snapshot.docs.map((doc) => ({ id: doc.id, ...doc.data() })); + setIncidents(incidentsArray); + }); + }, []); + // Ensure Firebase is initialized before using it if (!getApp().length) { initializeApp(firebaseConfig); @@ -162,10 +172,14 @@ const db = getFirestore(getApp());

Existing incidents in the database:

{incidents.map((incident) => (
-

{incident.submitter}

-

{incident.date}

-

{incident.context}

-

{incident.selectedOptions}

+

What date did this shennanigans occur?: + {incident.date}

+

Who submitted this: + {incident.submitter}

+

What caused Ray's moment?: + {incident.context}

+

What word's did Ray use this time?: + {incident.selectedOptions}

))}