-
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
d5f3dbb
commit bacdbfd
Showing
5 changed files
with
73 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'; | ||
|
||
export const contactsApi = createApi({ | ||
reducerPath: 'Contacts', | ||
baseQuery: fetchBaseQuery({ | ||
baseUrl: 'https://64a00809ed3c41bdd7a6ed28.mockapi.io', | ||
}), | ||
tagTypes: ['Contact'], | ||
endpoints: builder => ({ | ||
getContacts: builder.query({ | ||
query: () => `/Contacts`, | ||
providesTags: ['Contact'], | ||
}), | ||
|
||
addContact: builder.mutation({ | ||
query: ({ name, number }) => ({ | ||
url: '/Contacts', | ||
method: 'POST', | ||
body: { name, number }, | ||
}), | ||
invalidatesTags: ['Contact'], | ||
}), | ||
|
||
deleteContact: builder.mutation({ | ||
query: id => ({ | ||
url: `/Contacts/${id}`, | ||
method: 'DELETE', | ||
}), | ||
invalidatesTags: ['Contact'], | ||
}), | ||
}), | ||
}); | ||
|
||
export const { | ||
useGetContactsQuery, | ||
useAddContactMutation, | ||
useDeleteContactMutation, | ||
} = contactsApi; |
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,16 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
|
||
const filterInitialState = ''; | ||
|
||
export const filterSlice = createSlice({ | ||
name: 'filter', | ||
initialState: filterInitialState, | ||
reducers: { | ||
updateFilterValue(_, { payload }) { | ||
return payload; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { updateFilterValue } = filterSlice.actions; | ||
export const filterReducer = filterSlice.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 @@ | ||
export const getFilter = state => state.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { configureStore } from '@reduxjs/toolkit'; | ||
import { setupListeners } from '@reduxjs/toolkit/query'; | ||
|
||
import { filterReducer } from './filterSlice'; | ||
import { contactsApi } from './contactsSlice'; | ||
|
||
export const store = configureStore({ | ||
reducer: { | ||
[contactsApi.reducerPath]: contactsApi.reducer, | ||
filter: filterReducer, | ||
}, | ||
middleware: getDefaultMiddleware => [ | ||
...getDefaultMiddleware(), | ||
contactsApi.middleware, | ||
], | ||
}); | ||
|
||
setupListeners(store.dispatch); |
Empty file.