Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
kuciapakrystian committed May 26, 2024
1 parent d5f3dbb commit bacdbfd
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/Redux/contactsSlice.js
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;
16 changes: 16 additions & 0 deletions src/Redux/filterSlice.js
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;
1 change: 1 addition & 0 deletions src/Redux/selectors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const getFilter = state => state.filter;
18 changes: 18 additions & 0 deletions src/Redux/store.js
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 added src/Styles/GlobalStyles.jsx
Empty file.

0 comments on commit bacdbfd

Please sign in to comment.