Working code, need to fix Database formatting

This commit is contained in:
Ray 2023-12-29 09:33:19 +00:00 committed by GitHub
parent 3e3416fb12
commit 43f6954f53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 4 deletions

View File

@ -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());
<h2>Existing incidents in the database:</h2>
{incidents.map((incident) => (
<div key={incident.id}>
<h2>{incident.submitter}</h2>
<h3>{incident.date}</h3>
<h3>{incident.context}</h3>
<h3>{incident.selectedOptions}</h3>
<h3 bold>What date did this shennanigans occur?:
{incident.date}</h3>
<h2>Who submitted this:
{incident.submitter}</h2>
<h2>What caused Ray's moment?:
{incident.context}</h2>
<h2>What word's did Ray use this time?:
{incident.selectedOptions}</h2>
</div>
))}
</Form.Group>