import { createSlice , PayloadAction } from '@reduxjs/toolkit' ; import type { GroupInfo } from '../../model/group' ; export interface GroupState { groups : Record < string , GroupInfo > ; } const initialState = { groups : { } } ; const groupSlice = createSlice ( { name : 'group' , initialState , reducers : { /**
         * 追加或更新群组信息
         */ appendGroups ( state , action ) { const groups = action . payload ; for ( const group of groups ) { state . groups [ group . _id ] = { ... state . groups [ group . _id ] , ... group } ; } } , updateGroup ( state , action ) { const group = action . payload ; const groupId = group . _id ; if ( state . groups [ groupId ] ) { state . groups [ groupId ] = { ... state . groups [ groupId ] , ... group } ; } } , removeGroup ( state , action ) { const groupId = action . payload ; delete state . groups [ groupId ] ; } } } ) ; export const groupActions = groupSlice . actions ; export const groupReducer = groupSlice . reducer ;