Skip to content

Commit

Permalink
update App.jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
danretegan committed Feb 25, 2024
1 parent d63f4a1 commit ff3d74e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 29 deletions.
39 changes: 17 additions & 22 deletions src/components/App.jsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import React, { useState } from 'react';
import { nanoid } from 'nanoid';
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';

const App = () => {
const [contacts, setContacts] = useState([
{ id: 'id-0', name: 'Dan Retegan', number: '+40 753 023 616' },
{ id: 'id-1', name: 'Rosie Simpson', number: '459-123-563' },
{ id: 'id-2', name: 'Hermione Kant', number: '443 (895) 123' },
{ id: 'id-3', name: 'Eden Clements', number: '645-177-799' },
{
id: 'id-4',
name: "Charles de-Batz de Castelmore d'Artagnan",
number: '+01 227-911-266',
},
]);
const [filter, setFilter] = useState(''); // Adăugăm un câmp pentru filtrare
const contacts = useSelector(state => state.contacts);
const filter = useSelector(state => state.filter);
const dispatch = useDispatch();

const handleAddContact = (name, number) => {
if (name.trim() !== '' && number.trim() !== '') {
Expand All @@ -27,26 +22,26 @@ const App = () => {
number: number.trim(),
};

setContacts(prevContacts => [...prevContacts, newContact]);
dispatch(addContact(newContact));
}
};

const handleFilterChange = event => {
const { value } = event.target;
setFilter(value);
const handleDeleteContact = contactId => {
dispatch(deleteContact(contactId));
};

const handleDeleteContact = contactId => {
setContacts(prevContacts =>
prevContacts.filter(contact => contact.id !== contactId)
);
const handleFilterChange = event => {
const { value } = event.target;
console.log('New filter value:', value);
dispatch(setFilter(value));
};

// Filtrăm contactele în funcție de șirul de căutare:
const filteredContacts = contacts.filter(contact =>
contact.name.toLowerCase().includes(filter.toLowerCase())
);

console.log('filteredContacts:', filteredContacts);
return (
<div className={styles.container}>
<h1>Phonebook</h1>
Expand Down
2 changes: 1 addition & 1 deletion src/components/contactForm/ContactForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Button from '../Button';
import styles from './ContactForm.module.css';

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

const ContactForm = () => {
Expand Down
10 changes: 5 additions & 5 deletions src/components/contactList/ContactList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import PropTypes from 'prop-types';
import styles from './ContactList.module.css';
import ContactItem from '../contactItem/ContactItem';

import { useDispatch, useSelector } from 'react-redux';
import { deleteContact } from 'redux/slices/contactsSlice';
import { useDispatch } from 'react-redux';
import { deleteContact } from '../../redux/slices/contactsSlice';

const ContactList = () => {
const dispatch = useDispatch();
const contacts = useSelector(state => state.contacts);
const ContactList = ({ contacts }) => {
console.log('Contacts in ContactList:', contacts);

const dispatch = useDispatch();
const handleDeleteContact = contactId => {
dispatch(deleteContact(contactId));
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/searchFilter/SearchFilter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import styles from './SearchFilter.module.css';

import { useDispatch, useSelector } from 'react-redux';
import { setFilter } from 'redux/slices/filterSlice';
import { setFilter } from '../../redux/slices/filterSlice';

const SearchFilter = () => {
const dispatch = useDispatch();
Expand Down

0 comments on commit ff3d74e

Please sign in to comment.