mirror of https://github.com/msgbyte/tailchat
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
674 B
TypeScript
31 lines
674 B
TypeScript
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
|
import type { GroupInfo } from '../../model/group';
|
|
|
|
interface GroupState {
|
|
groups: Record<string, GroupInfo>;
|
|
}
|
|
|
|
const initialState: GroupState = {
|
|
groups: {},
|
|
};
|
|
|
|
const groupSlice = createSlice({
|
|
name: 'group',
|
|
initialState,
|
|
reducers: {
|
|
appendGroups(state, action: PayloadAction<GroupInfo[]>) {
|
|
const groups = action.payload;
|
|
|
|
for (const group of groups) {
|
|
state.groups[group._id] = {
|
|
...state.groups[group._id],
|
|
...group,
|
|
};
|
|
}
|
|
},
|
|
},
|
|
});
|
|
|
|
export const groupActions = groupSlice.actions;
|
|
export const groupReducer = groupSlice.reducer;
|