add option for "bruh" and formatted document

This commit is contained in:
Ray 2023-12-29 10:40:01 +00:00 committed by GitHub
parent c9a0822f3b
commit d7e51ff304
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 26 deletions

View File

@ -32,6 +32,7 @@
from { from {
transform: rotate(0deg); transform: rotate(0deg);
} }
to { to {
transform: rotate(360deg); transform: rotate(360deg);
} }

View File

@ -19,7 +19,7 @@ import './App.css'
if (!getApps().length) { if (!getApps().length) {
initializeApp(firebaseConfig); initializeApp(firebaseConfig);
} }
// declare variables // declare variables
@ -31,21 +31,21 @@ export function MyForm(props) {
const [incidents, setIncidents] = useState([]); // Declare incidents as an empty array const [incidents, setIncidents] = useState([]); // Declare incidents as an empty array
// Fetch incidents from Firestore when the component mounts // Fetch incidents from Firestore when the component mounts
useEffect(() => { useEffect(() => {
const incidentsRef = collection(db, "incidents"); const incidentsRef = collection(db, "incidents");
getDocs(incidentsRef).then((snapshot) => { getDocs(incidentsRef).then((snapshot) => {
const incidentsArray = snapshot.docs.map((doc) => ({ id: doc.id, ...doc.data() })); const incidentsArray = snapshot.docs.map((doc) => ({ id: doc.id, ...doc.data() }));
setIncidents(incidentsArray); setIncidents(incidentsArray);
}); });
}, []); }, []);
// Ensure Firebase is initialized before using it // Ensure Firebase is initialized before using it
if (!getApp().length) { if (!getApp().length) {
initializeApp(firebaseConfig); initializeApp(firebaseConfig);
} }
const db = getFirestore(getApp()); const db = getFirestore(getApp());
// Create a function to handle the checkbox changes and update the state accordingly. // Create a function to handle the checkbox changes and update the state accordingly.
@ -61,13 +61,13 @@ const db = getFirestore(getApp());
// Create a function to handle the form submission and add data to Firebase. NOT WORKING // Create a function to handle the form submission and add data to Firebase. NOT WORKING
const submitHandler = async (event) => { const submitHandler = async (event) => {
event.preventDefault() event.preventDefault()
const incidentsData = { submitter, date, context, selectedOptions } // Use the state variables directly const incidentsData = { submitter, date, context, selectedOptions } // Use the state variables directly
const col = collection(db, `incidents`) const col = collection(db, `incidents`)
const ref = await addDoc(col, incidentsData) const ref = await addDoc(col, incidentsData)
console.log(ref) console.log(ref)
} }
// Create form for user to imput data // Create form for user to imput data
return ( return (
@ -134,7 +134,7 @@ const db = getFirestore(getApp());
onChange={handleCheckboxChange} onChange={handleCheckboxChange}
/> />
<Form.Check <Form.Check
type="checkbox" type="checkbox"
label="sus" label="sus"
value="sus" value="sus"
@ -142,7 +142,7 @@ const db = getFirestore(getApp());
onChange={handleCheckboxChange} onChange={handleCheckboxChange}
/> />
<Form.Check <Form.Check
type="checkbox" type="checkbox"
label="fr fr" label="fr fr"
value="fr fr" value="fr fr"
@ -150,19 +150,24 @@ const db = getFirestore(getApp());
onChange={handleCheckboxChange} onChange={handleCheckboxChange}
/> />
<Form.Check <Form.Check
type="checkbox" type="checkbox"
label="balls" label="balls"
value="balls" value="balls"
checked={selectedOptions.includes('balls')} checked={selectedOptions.includes('balls')}
onChange={handleCheckboxChange} onChange={handleCheckboxChange}
/> />
<Form.Check
type="checkbox"
label="bruh"
value="bruh"
checked={selectedOptions.includes('bruh')}
onChange={handleCheckboxChange} />
<Button type="submit">Submit</Button> <Button type="submit">Submit</Button>
</Col> </Col>
</Form.Group> </Form.Group>
<p>Refresh once submitted to see result added below.</p> <p>Refresh once submitted to see result added below.</p>
<Form.Group> <Form.Group>
<h2>Existing incidents in the database:</h2> <h2>Existing incidents in the database:</h2>
@ -183,7 +188,7 @@ const db = getFirestore(getApp());
</Form.Group> </Form.Group>
</Form> </Form>
</div> </div>
// Create a form group to display the existing entries in the database. // Create a form group to display the existing entries in the database.
); );
} }
export default MyForm; export default MyForm;