From ffc08b1cf90e46cae41b61984bfc3e5dd2cdba46 Mon Sep 17 00:00:00 2001 From: yinxin630 Date: Mon, 9 Apr 2018 19:27:56 +0800 Subject: [PATCH] feat: Show user groups --- .../featureLinkmans/FeatureLinkmans.jsx | 28 +---------- .../featureLinkmans/LinkmanGroup.jsx | 46 ++++++++++++++----- package.json | 1 + yarn.lock | 4 ++ 4 files changed, 41 insertions(+), 38 deletions(-) diff --git a/client/modules/main/chatPanel/featureLinkmans/FeatureLinkmans.jsx b/client/modules/main/chatPanel/featureLinkmans/FeatureLinkmans.jsx index 5b5434d38..394591808 100644 --- a/client/modules/main/chatPanel/featureLinkmans/FeatureLinkmans.jsx +++ b/client/modules/main/chatPanel/featureLinkmans/FeatureLinkmans.jsx @@ -1,39 +1,13 @@ import React, { Component } from 'react'; import LinkmanGroup from './LinkmanGroup'; -import Linkman from './Linkman'; import './FeatureLinkmans.less'; class FeatureLinkmans extends Component { render() { return (
- - - - - +
); } diff --git a/client/modules/main/chatPanel/featureLinkmans/LinkmanGroup.jsx b/client/modules/main/chatPanel/featureLinkmans/LinkmanGroup.jsx index 5dbaef20b..9502a81ac 100644 --- a/client/modules/main/chatPanel/featureLinkmans/LinkmanGroup.jsx +++ b/client/modules/main/chatPanel/featureLinkmans/LinkmanGroup.jsx @@ -1,36 +1,60 @@ import React, { Component } from 'react'; -import PropTypes from 'prop-types'; +import { connect } from 'react-redux'; +import ImmutablePropTypes from 'react-immutable-proptypes'; + +import Linkman from './Linkman'; class LinkmanGroup extends Component { static propTypes = { - children: PropTypes.arrayOf(PropTypes.element), - defaultFocus: PropTypes.string, + groups: ImmutablePropTypes.list, } constructor(props) { super(props); this.state = { - focus: props.defaultFocus, + focus: '', }; } + componentWillReceiveProps(nextProps) { + if (nextProps.groups.length !== 0) { + this.setState({ + focus: nextProps.groups.getIn(['0', '_id']), + }); + } + } changeFocus(focus) { this.setState({ focus, }); } + renderGroup(group) { + const groupId = group.get('_id'); + return ( + + ); + } render() { - const { children } = this.props; - const { focus } = this.state; + const { groups } = this.props; return (
{ - children.map(linkman => React.cloneElement(linkman, { - focus: focus === linkman.key, - onClick: this.changeFocus.bind(this, linkman.key), - })) + groups.map(group => ( + this.renderGroup(group) + )) }
); } } -export default LinkmanGroup; +export default connect(state => ({ + groups: state.getIn(['user', 'groups']) || [], +}))(LinkmanGroup); diff --git a/package.json b/package.json index 15874900c..2d02407ac 100644 --- a/package.json +++ b/package.json @@ -82,6 +82,7 @@ "prop-types": "^15.6.0", "pxrem-loader": "^1.0.0", "react-hot-loader": "^4.0.0", + "react-immutable-proptypes": "^2.1.0", "react-transform-log-render": "^1.0.0", "react-transform-style": "^1.0.4", "redbox-react": "^1.3.4", diff --git a/yarn.lock b/yarn.lock index 38de4b36e..6b343b618 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5681,6 +5681,10 @@ react-hot-loader@^4.0.0: prop-types "^15.6.0" shallowequal "^1.0.2" +react-immutable-proptypes@^2.1.0: + version "2.1.0" + resolved "https://registry.npmjs.org/react-immutable-proptypes/-/react-immutable-proptypes-2.1.0.tgz#023d6f39bb15c97c071e9e60d00d136eac5fa0b4" + react-immutable-render-mixin@^0.9.7: version "0.9.7" resolved "http://registry.npm.taobao.org/react-immutable-render-mixin/download/react-immutable-render-mixin-0.9.7.tgz#fe34053760cc72e7becc8af3e6e30542d97d3601"