Skip to content

Commit

Permalink
clean App.jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
danretegan committed Mar 7, 2024
1 parent f27f83e commit bb046e0
Showing 1 changed file with 7 additions and 46 deletions.
53 changes: 7 additions & 46 deletions src/components/App.jsx
Original file line number Diff line number Diff line change
@@ -1,63 +1,24 @@
// App.jsx

import React from 'react';
import ContactForm from './contactForm/ContactForm';
import ContactList from './contactList/ContactList';
import SearchFilter from './searchFilter/SearchFilter';
import styles from './App.module.css';

import { useSelector, useDispatch } from 'react-redux';
import { nanoid } from '@reduxjs/toolkit';

import { addContact, deleteContact } from '../redux/slices/contactsSlice';
import { setFilter } from '../redux/slices/filterSlice';

// Importăm selectorii din selectors.js:
import {
selectContacts,
selectFilter,
selectFilteredContacts,
} from '../redux/selectors';
import { useSelector } from 'react-redux';
import { selectFilteredContacts } from '../redux/selectors';

const App = () => {
// Folosim selectorii pentru a obține informațiile necesare:
const contacts = useSelector(selectContacts);
const filter = useSelector(selectFilter);
const filteredContacts = useSelector(selectFilteredContacts);
const dispatch = useDispatch();

const handleAddContact = (name, number) => {
if (name.trim() !== '' && number.trim() !== '') {
const newContact = {
id: nanoid(),
name: name.trim(),
number: number.trim(),
};

dispatch(addContact(newContact));
}
};

const handleDeleteContact = contactId => {
dispatch(deleteContact(contactId));
};

const handleFilterChange = event => {
const { value } = event.target;
console.log('New filter value:', value);
dispatch(setFilter(value));
};

console.log('filteredContacts:', filteredContacts);
return (
<div className={styles.container}>
<h1>Phonebook</h1>
<ContactForm onAddContact={handleAddContact} contacts={contacts} />
<ContactForm />
<h2>Contacts:</h2>
<SearchFilter filter={filter} onFilterChange={handleFilterChange} />
<ContactList
contacts={filteredContacts}
onDeleteContact={handleDeleteContact}
className={styles.list}
/>
<SearchFilter />
<ContactList contacts={filteredContacts} />
</div>
);
};
Expand Down

0 comments on commit bb046e0

Please sign in to comment.