Skip to content

Commit

Permalink
feat(group): 增加处理更新团信息的通知
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed Feb 28, 2020
1 parent bf910f4 commit bf8772f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
5 changes: 5 additions & 0 deletions src/shared/api/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function bindEventFunc(
addGroupMember,
removeGroupMember,
updateGroupActorInfo,
updateGroupInfo,
} = require('../redux/actions/group');
const { getUserInfoCache } = require('../utils/cache-helper');

Expand Down Expand Up @@ -79,6 +80,10 @@ export function bindEventFunc(
api.on('group::addGroupSuccess', function(data) {
store.dispatch(addGroup(data.group));
});
api.on('group::updateInfo', function(data) {
const { groupUUID, groupInfo } = data;
store.dispatch(updateGroupInfo(groupUUID, groupInfo));
});
api.on('group::updateGroupActorInfo', function(data) {
const { groupUUID, groupActorUUID, groupActorInfo } = data;
store.dispatch(
Expand Down
12 changes: 9 additions & 3 deletions src/shared/redux/actions/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import constants from '../constants';
const {
CREATE_GROUP_SUCCESS,
GET_GROUP_INFO_SUCCESS,
UPDATE_GROUP_INFO_SUCCESS,
UPDATE_GROUP_INFO,
FIND_GROUP_REQUEST,
FIND_GROUP_SUCCESS,
REQUEST_JOIN_GROUP_SUCCESS,
Expand Down Expand Up @@ -194,13 +194,16 @@ export const getGroupInfo = function(uuid: string): TRPGAction {
* @param groupUUID 团UUID
* @param groupInfo 团信息
*/
export const updateGroupInfo = function(groupUUID, groupInfo) {
export const requestUpdateGroupInfo = function(
groupUUID: string,
groupInfo: object
) {
return function(dispatch, getState) {
api.emit('group::updateInfo', { groupUUID, groupInfo }, function(data) {
if (data.result) {
let group = data.group;
group.avatar = config.file.getAbsolutePath(group.avatar);
dispatch({ type: UPDATE_GROUP_INFO_SUCCESS, payload: group });
dispatch(updateGroupInfo(group));
dispatch(hideModal());
dispatch(showAlert('操作成功'));
} else {
Expand All @@ -210,6 +213,9 @@ export const updateGroupInfo = function(groupUUID, groupInfo) {
});
};
};
export function updateGroupInfo(groupInfo: object): TRPGAction {
return { type: UPDATE_GROUP_INFO, payload: groupInfo };
}

export const findGroup = function(text, type) {
return function(dispatch, getState) {
Expand Down
2 changes: 1 addition & 1 deletion src/shared/redux/constants/group.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default {
CREATE_GROUP_SUCCESS: 'CREATE_GROUP_SUCCESS',
GET_GROUP_INFO_SUCCESS: 'GET_GROUP_INFO_SUCCESS',
UPDATE_GROUP_INFO_SUCCESS: 'UPDATE_GROUP_INFO_SUCCESS',
UPDATE_GROUP_INFO: 'UPDATE_GROUP_INFO',
FIND_GROUP_REQUEST: 'FIND_GROUP_REQUEST',
FIND_GROUP_SUCCESS: 'FIND_GROUP_SUCCESS',
REQUEST_JOIN_GROUP_SUCCESS: 'REQUEST_JOIN_GROUP_SUCCESS',
Expand Down
4 changes: 2 additions & 2 deletions src/shared/redux/reducers/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {
RESET,
CREATE_GROUP_SUCCESS,
GET_GROUP_INFO_SUCCESS,
UPDATE_GROUP_INFO_SUCCESS,
UPDATE_GROUP_INFO,
FIND_GROUP_REQUEST,
FIND_GROUP_SUCCESS,
REQUEST_JOIN_GROUP_SUCCESS,
Expand Down Expand Up @@ -86,7 +86,7 @@ export default produce((draft: GroupState, action) => {

// return state.mergeIn(['info', groupUUID], fromJS(action.payload)); // 合并
}
case UPDATE_GROUP_INFO_SUCCESS: {
case UPDATE_GROUP_INFO: {
const groupIndex = draft.groups.findIndex(
(i) => i.uuid === action.payload.uuid
);
Expand Down
6 changes: 3 additions & 3 deletions src/web/components/modal/GroupEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import config from '../../../shared/project.config';
import ModalPanel from '../ModalPanel';
import ImageUploader from '../ImageUploader';
import { hideModal } from '../../../shared/redux/actions/ui';
import { updateGroupInfo } from '../../../shared/redux/actions/group';
import { requestUpdateGroupInfo } from '../../../shared/redux/actions/group';

import './GroupEdit.scss';
import { TRPGState, TRPGDispatchProp } from '@redux/types/__all__';
Expand Down Expand Up @@ -34,13 +34,13 @@ class GroupEdit extends React.Component<Props, State> {
const groupInfoData: State = Object.assign({}, this.state);
delete groupInfoData.avatar;
this.props.dispatch(
updateGroupInfo(this.props.selectedGroupUUID, groupInfoData)
requestUpdateGroupInfo(this.props.selectedGroupUUID, groupInfoData)
);
}

handleUpdateAvatar(url: string) {
this.props.dispatch(
updateGroupInfo(this.props.selectedGroupUUID, { avatar: url })
requestUpdateGroupInfo(this.props.selectedGroupUUID, { avatar: url })
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/web/containers/main/group/modal/GroupRuleEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import TRPGEditor from '@shared/editor';
import { Button } from 'antd';
import { useSelector, useDispatch } from 'react-redux';
import { TRPGState } from '@redux/types/__all__';
import { updateGroupInfo } from '@redux/actions/group';
import { requestUpdateGroupInfo } from '@redux/actions/group';
import { GroupInfo } from '@redux/types/group';

interface Props {}
Expand All @@ -21,7 +21,7 @@ const GroupRuleEditor: React.FC<Props> = React.memo((props) => {

const handleSave = useCallback(() => {
dispatch(
updateGroupInfo(groupUUID, {
requestUpdateGroupInfo(groupUUID, {
rule: content,
})
);
Expand Down

0 comments on commit bf8772f

Please sign in to comment.