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}

))}