-
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.
Task completed, code refactored to thunk
- Loading branch information
Showing
14 changed files
with
218 additions
and
79 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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,11 +1,11 @@ | ||
const { createAction } = require('@reduxjs/toolkit'); | ||
|
||
export const addContact = createAction('contacts/addContact'); | ||
export const getContact = createAction('contacts/addContact'); | ||
|
||
export const removeContact = createAction('contacts/removeContact'); | ||
// export const removeContact = createAction('contacts/removeContact'); | ||
|
||
export const getContacts = createAction('contacts/getContacts'); | ||
// export const getContacts = createAction('contacts/getContacts'); | ||
|
||
export const loadContacts = createAction('contacts/loadContacts'); | ||
// export const loadContacts = createAction('contacts/loadContacts'); | ||
|
||
export const setStatusFilter = createAction('filter/setStatusFilter'); |
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,48 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
// Importujemy operację | ||
import { fetchContacts, addContact, deleteContact } from './operations'; | ||
const handleRejected = (state, action) => { | ||
state.error = action.payload; | ||
state.isLoading = false; | ||
}; | ||
|
||
const handlePending = state => { | ||
state.isLoading = true; | ||
}; | ||
|
||
const contactsSlice = createSlice({ | ||
name: 'contacts', | ||
initialState: { | ||
items: [], | ||
isLoading: true, | ||
error: null, | ||
}, | ||
extraReducers: { | ||
[fetchContacts.pending]: handlePending, | ||
[fetchContacts.fulfilled](state, action) { | ||
state.isLoading = false; | ||
state.items = action.payload; | ||
state.error = null; | ||
}, | ||
[fetchContacts.rejected]: handleRejected, | ||
[addContact.pending]: handlePending, | ||
[addContact.fulfilled](state, action) { | ||
state.isLoading = false; | ||
state.error = null; | ||
state.items.push(action.payload); | ||
}, | ||
[addContact.rejected]: handleRejected, | ||
[deleteContact.pending]: handlePending, | ||
[deleteContact.fulfilled](state, action) { | ||
state.isLoading = false; | ||
state.error = null; | ||
const index = state.items.findIndex( | ||
item => item.id === action.payload.id | ||
); | ||
state.items.splice(index, 1); | ||
}, | ||
[deleteContact.rejected]: handleRejected, | ||
}, | ||
}); | ||
|
||
export const contactsReducer = 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,15 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
|
||
const filterSlice = createSlice({ | ||
name: 'filter', | ||
initialState: '', | ||
|
||
reducers: { | ||
setStatusFilter(_, action) { | ||
return action.payload; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { setStatusFilter } = filterSlice.actions; | ||
export const filterReducer = filterSlice.reducer; |
Oops, something went wrong.