feat: users online status
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
const initialState = [];
|
||||
const contactsSlice = createSlice({
|
||||
name: `contacts`,
|
||||
initialState,
|
||||
reducers: {
|
||||
setContacts(state, action) {
|
||||
console.log("set Contacts store", state);
|
||||
const contacts = action.payload || [];
|
||||
return contacts;
|
||||
},
|
||||
updateUsersStatus(state, action) {
|
||||
const onlines = action.payload;
|
||||
onlines.forEach((item) => {
|
||||
const { uid, online = false } = item;
|
||||
const curr = state.find(({ uid: id }) => id == uid);
|
||||
console.log("update user status", curr, online);
|
||||
if (curr) {
|
||||
curr.online = online;
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
export const { setContacts, updateUsersStatus } = contactsSlice.actions;
|
||||
export default contactsSlice.reducer;
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
import authDataReducer from "./slices/auth.data";
|
||||
import uiReducer from "./slices/ui";
|
||||
import channelsReducer from "./slices/channels";
|
||||
import contactsReducer from "./slices/contacts";
|
||||
import channelMsgReducer from "./slices/message.channel";
|
||||
import userMsgReducer from "./slices/message.user";
|
||||
import { authApi } from "./services/auth";
|
||||
@@ -28,6 +29,7 @@ const persistedReducer = persistReducer(
|
||||
persistConfig,
|
||||
combineReducers({
|
||||
ui: uiReducer,
|
||||
contacts: contactsReducer,
|
||||
channels: channelsReducer,
|
||||
userMsg: userMsgReducer,
|
||||
channelMsg: channelMsgReducer,
|
||||
@@ -53,4 +55,27 @@ const store = configureStore({
|
||||
),
|
||||
});
|
||||
setupListeners(store.dispatch);
|
||||
// export function swapToUserStore(userId) {
|
||||
// console.log({ userId });
|
||||
// const newConfig = {
|
||||
// ...persistConfig,
|
||||
// keyPrefix: userId,
|
||||
// };
|
||||
// store.replaceReducer(
|
||||
// persistReducer(
|
||||
// newConfig,
|
||||
// combineReducers({
|
||||
// ui: uiReducer,
|
||||
// channels: channelsReducer,
|
||||
// userMsg: userMsgReducer,
|
||||
// channelMsg: channelMsgReducer,
|
||||
// authData: authDataReducer,
|
||||
// [authApi.reducerPath]: authApi.reducer,
|
||||
// [contactApi.reducerPath]: contactApi.reducer,
|
||||
// [channelApi.reducerPath]: channelApi.reducer,
|
||||
// [serverApi.reducerPath]: serverApi.reducer,
|
||||
// })
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
export default store;
|
||||
|
||||
Reference in New Issue
Block a user