Skip to content

Commit

Permalink
fix: app filterForm add toLowerCase()
Browse files Browse the repository at this point in the history
  • Loading branch information
AM1007 committed Feb 16, 2024
1 parent 20070c6 commit 934d69d
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand All @@ -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] }));
Expand All @@ -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;
Expand All @@ -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 (
<div>
<h1>
Phonebook
</h1>
<h1>Phonebook</h1>
<Section title="Phonebook">
<ContactForm onSubmit={this.formSubmit} />
</Section>
Expand Down

0 comments on commit 934d69d

Please sign in to comment.