diff --git a/React/src/app/page.tsx b/React/src/app/page.tsx index 21e0862..f34f37b 100644 --- a/React/src/app/page.tsx +++ b/React/src/app/page.tsx @@ -3,7 +3,7 @@ import { useState, useEffect } from "react"; import { useRouter } from "next/navigation"; export default function Home() { - const [contacts, setContacts] = useState([]); + const [contacts, setContacts] = useState([""]); const [codeword, setCodeword] = useState(""); const [session, setSession] = useState(null); const [loading, setLoading] = useState(true); @@ -23,6 +23,16 @@ export default function Home() { }); }, []); + const handleInputChange = (index: number, value: string) => { + const updatedContacts = [...contacts]; + updatedContacts[index] = value; // Update the specific input value + setContacts(updatedContacts); + }; + + const addContactInput = () => { + setContacts([...contacts, ""]); // Add a new empty input + }; + function saveToDB() { alert("Saving contacts..."); const contactInputs = document.querySelectorAll( @@ -181,45 +191,20 @@ export default function Home() { className="space-y-5 flex flex-col gap-[32px] row-start-2 items-center sm:items-start" onSubmit={(e) => e.preventDefault()} > - setContacts(e.target.value.split(","))} - placeholder="Write down an emergency contact" - className="border border-gray-300 rounded-md p-2" - /> - setContacts(e.target.value.split(","))} - placeholder="Write down an emergency contact" - className="border border-gray-300 rounded-md p-2" - /> - setContacts(e.target.value.split(","))} - placeholder="Write down an emergency contact" - className="border border-gray-300 rounded-md p-2" - /> - setContacts(e.target.value.split(","))} - placeholder="Write down an emergency contact" - className="text-input border border-gray-300 rounded-md p-2" - /> + {contacts.map((contact, index) => ( + handleInputChange(index, e.target.value)} + placeholder={`Contact ${index + 1}`} + className="border border-gray-300 rounded-md p-2" + /> + ))}