From 934d69d7530ad574a412717f9df88fd4c0472968 Mon Sep 17 00:00:00 2001 From: Andrew Motko Date: Fri, 16 Feb 2024 14:28:08 +0200 Subject: [PATCH] fix: app filterForm add toLowerCase() --- src/components/App.jsx | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/components/App.jsx b/src/components/App.jsx index 7161089..0fec064 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -7,7 +7,6 @@ import { ContactList } from './ContactList/ContactList'; import { Filter } from './Filter/Filter'; export class App extends Component { - state = { contacts: [ { id: 'id-1', name: 'Rosie Simpson', number: '459-12-56' }, @@ -20,10 +19,15 @@ export class App extends Component { formSubmit = ({ name, number }) => { const contact = { id: nanoid(), name, number }; - - if (this.state.contacts.some(e => e.name === name)) { - return alert(`${name} is already in contacts!`); + const lowerCaseName = name.toLowerCase(); + + if ( + this.state.contacts.some( + contact => contact.name.toLowerCase() === lowerCaseName + ) + ) { + return alert(`${name} is already in contacts!`); } this.setState(({ contacts }) => ({ contacts: [contact, ...contacts] })); @@ -32,8 +36,7 @@ export class App extends Component { getFilteredContacts = () => { const { contacts, filter } = this.state; const filterContactsList = contacts.filter(contact => { - - return contact.name.toLowerCase().includes(filter.toLowerCase()); + return contact.name.toLowerCase().includes(filter.toLowerCase()); }); return filterContactsList; @@ -44,22 +47,19 @@ export class App extends Component { this.setState({ [name]: value }); }; - + deleteContact = contactId => { - this.setState(prevState => ({ contacts: prevState.contacts.filter(contact => contact.id !== contactId), })); }; render() { - const {filter} = this.state; + const { filter } = this.state; return (
-

- Phonebook -

+

Phonebook