Skip to content

Commit 13d32af

Browse files
committed
perf: optimize the update group configuration interaction under low-speed network
1 parent b3d80c4 commit 13d32af

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

client/shared/model/group.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export const groupConfigNames = [
1010
// 隐藏群组成员标识位
1111
'hideGroupMemberDiscriminator',
1212

13+
// 禁止从群组中发起私信
14+
'disableCreateConverseFromGroup',
15+
1316
// 群组背景图
1417
'groupBackgroundImage',
1518
] as const;

client/shared/redux/slices/group.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,27 @@ const groupSlice = createSlice({
7575
};
7676
}
7777
},
78+
updateGroupConfig(
79+
state,
80+
action: PayloadAction<{
81+
groupId: string;
82+
configName: string;
83+
configValue: any;
84+
}>
85+
) {
86+
const { groupId, configName, configValue } = action.payload;
87+
88+
const groupInfo = state.groups[groupId];
89+
if (groupInfo) {
90+
state.groups[groupId] = {
91+
...groupInfo,
92+
config: {
93+
...(groupInfo.config ?? {}),
94+
[configName]: configValue,
95+
},
96+
};
97+
}
98+
},
7899
},
79100
});
80101

client/web/src/components/modals/GroupDetail/Config.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import React from 'react';
22
import {
3+
groupActions,
34
model,
45
showSuccessToasts,
56
t,
67
UploadFileResult,
8+
useAppDispatch,
79
useAsyncRequest,
810
useGroupInfo,
911
} from 'tailchat-shared';
@@ -21,10 +23,18 @@ export const GroupConfig: React.FC<{
2123
}> = React.memo((props) => {
2224
const groupId = props.groupId;
2325
const groupInfo = useGroupInfo(groupId);
26+
const dispatch = useAppDispatch();
2427

2528
const [{ loading }, handleModifyConfig] = useAsyncRequest(
2629
async (configName: model.group.GroupConfigNames, configValue: any) => {
2730
await model.group.modifyGroupConfig(groupId, configName, configValue);
31+
dispatch(
32+
groupActions.updateGroupConfig({
33+
groupId,
34+
configName,
35+
configValue,
36+
})
37+
);
2838
showSuccessToasts();
2939
},
3040
[groupId]

0 commit comments

Comments
 (0)