-
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
a8ca384
commit 9540f35
Showing
8 changed files
with
100 additions
and
62 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,25 @@ | ||
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'; | ||
|
||
|
||
export const channelsApi = createApi({ | ||
reducerPath: 'channels', | ||
baseQuery: fetchBaseQuery({ | ||
baseUrl: '/api/v1', | ||
prepareHeaders: (headers) => { | ||
const token = localStorage.getItem('token'); | ||
if (token) { | ||
headers.set('Authorization', `Bearer ${token}`); | ||
} | ||
return headers; | ||
} | ||
}), | ||
endpoints: (builder) => ({ | ||
getChannels: builder.query({ | ||
query: () => 'channels', | ||
}), | ||
}), | ||
}); | ||
|
||
export const { | ||
useGetChannelsQuery, | ||
} = channelsApi; |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
|
||
const initialState = { | ||
currentChannel: 1, | ||
}; | ||
|
||
const activeChannelSlice = createSlice({ | ||
name: 'activeChannel', | ||
initialState, | ||
reducers: { | ||
selectActiveTab: (state, { payload }) => { | ||
state.activeChannel = payload; | ||
}, | ||
}, | ||
}); | ||
|
||
export const activeChannelSelector = (state) => state.activeChannel.currentChannel; | ||
export const { selectActiveTab } = activeChannelSlice.actions; | ||
export default activeChannelSlice.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,8 +1,17 @@ | ||
import { configureStore } from '@reduxjs/toolkit'; | ||
import channelsReducer from './channelsSlice'; | ||
import { combineReducers, configureStore } from '@reduxjs/toolkit'; | ||
import { channelsApi } from '../api/channelsApi.js'; | ||
import activeChannelReducer from './activeChannelSlice.js'; | ||
|
||
export default configureStore({ | ||
reducer: { | ||
channels: channelsReducer, | ||
} | ||
}); | ||
const rootReducer = combineReducers({ | ||
[channelsApi.reducerPath]: channelsApi.reducer, | ||
activeChannel: activeChannelReducer, | ||
// messages: mesagesReducer, | ||
}); | ||
|
||
const store = configureStore ({ | ||
reducer: rootReducer, | ||
middleware: (getDefaultMiddleware) => | ||
getDefaultMiddleware().concat(channelsApi.middleware), | ||
}); | ||
|
||
export default store; |
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