From 9753d150025c52cc5df9e84bfa4cd41f49275ca3 Mon Sep 17 00:00:00 2001 From: counterweight Date: Sun, 25 May 2025 00:10:10 +0200 Subject: [PATCH] completed 2.7 --- parts/2/notes.md | 2 +- parts/2/phoneBook/src/App.jsx | 10 +++++++++- parts/2/phoneBook/src/components/PersonList.jsx | 5 +---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/parts/2/notes.md b/parts/2/notes.md index 6a37b74..768dbe5 100644 --- a/parts/2/notes.md +++ b/parts/2/notes.md @@ -5,7 +5,7 @@ Exercises: * [X] 2.4 * [X] 2.5 * [X] 2.6 -* [ ] 2.7 +* [X] 2.7 * [ ] 2.8 * [ ] 2.9 * [ ] 2.10 diff --git a/parts/2/phoneBook/src/App.jsx b/parts/2/phoneBook/src/App.jsx index 27d6b48..a84871d 100644 --- a/parts/2/phoneBook/src/App.jsx +++ b/parts/2/phoneBook/src/App.jsx @@ -7,7 +7,15 @@ const App = () => { const handleOnSubmit = (event) => { event.preventDefault(); - setPersons(persons.concat({ name: [newName] })); + if ( + persons.some((person) => { + return person.name === newName; + }) + ) { + alert(`${newName} is already in the phonebook.`); + return; + } + setPersons(persons.concat({ name: newName })); }; const handleNameChange = (event) => { diff --git a/parts/2/phoneBook/src/components/PersonList.jsx b/parts/2/phoneBook/src/components/PersonList.jsx index aa5501d..80da3a4 100644 --- a/parts/2/phoneBook/src/components/PersonList.jsx +++ b/parts/2/phoneBook/src/components/PersonList.jsx @@ -1,12 +1,9 @@ const PersonList = ({ persons }) => { - console.log("the list"); - console.log(persons); - return ( <>