generated from Sokilskill/goit-react-hw-04-phonebook
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62c4434
commit 0930375
Showing
9 changed files
with
92 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import css from './Filter.module.css'; | ||
import { useDispatch } from 'react-redux'; | ||
import { inputFilter } from 'redux/filterSlice.js/filterSlice'; | ||
|
||
const Filter = () => { | ||
const dispatch = useDispatch(); | ||
|
||
const handlerInputFilter = e => { | ||
const { value } = e.target; | ||
dispatch(inputFilter(value)); | ||
}; | ||
|
||
const Filter = ({ onChange, filterValue }) => { | ||
return ( | ||
<label className={css.label}> | ||
Find contacts by name: | ||
<input | ||
className={css.input} | ||
type="text" | ||
name="filter" | ||
value={filterValue} | ||
onChange={onChange} | ||
onChange={handlerInputFilter} | ||
/> | ||
</label> | ||
); | ||
}; | ||
|
||
Filter.propTypes = { | ||
onChange: PropTypes.func.isRequired, | ||
filterValue: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default Filter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { createSlice, nanoid } from '@reduxjs/toolkit'; | ||
import contactsTemplate from '../../data/contactsTemplate.json'; | ||
|
||
const contactsSlice = createSlice({ | ||
name: 'contacts', | ||
initialState: [...contactsTemplate], | ||
reducers: { | ||
addContact(state, { payload }) { | ||
return [{ id: nanoid(), ...payload }, ...state]; | ||
}, | ||
deleteContact(state, { payload }) { | ||
return state.filter(contact => contact.id !== payload); | ||
}, | ||
}, | ||
}); | ||
|
||
export const { addContact, deleteContact } = contactsSlice.actions; | ||
export default contactsSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
|
||
const filterSlice = createSlice({ | ||
name: 'filter', | ||
initialState: '', | ||
reducers: { | ||
inputFilter(state, { payload }) { | ||
return (state = payload); | ||
}, | ||
}, | ||
}); | ||
|
||
export const { inputFilter } = filterSlice.actions; | ||
export default filterSlice.reducer; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { configureStore } from '@reduxjs/toolkit'; | ||
import { myReducer, contactsRed } from './reducer'; | ||
import contactsSliceReducer from './contacts/contactsSlice'; | ||
import filterSliceReducer from './filterSlice.js/filterSlice'; | ||
|
||
export const store = configureStore({ | ||
reducer: { | ||
myValue: myReducer, | ||
contacts: contactsRed, | ||
contacts: contactsSliceReducer, | ||
filter: filterSliceReducer, | ||
}, | ||
}); |