forked from yinxin630/fiora
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
41 additions
and
38 deletions.
There are no files selected for viewing
28 changes: 1 addition & 27 deletions
28
client/modules/main/chatPanel/featureLinkmans/FeatureLinkmans.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 35 additions & 11 deletions
46
client/modules/main/chatPanel/featureLinkmans/LinkmanGroup.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<Linkman | ||
key={groupId} | ||
name={group.get('name')} | ||
avatar={group.get('avatar')} | ||
preview="1111111111#(乖)" | ||
time={new Date()} | ||
unread={9} | ||
focus={this.state.focus === groupId} | ||
onClick={this.changeFocus.bind(this, groupId)} | ||
/> | ||
); | ||
} | ||
render() { | ||
const { children } = this.props; | ||
const { focus } = this.state; | ||
const { groups } = this.props; | ||
return ( | ||
<div> | ||
{ | ||
children.map(linkman => React.cloneElement(linkman, { | ||
focus: focus === linkman.key, | ||
onClick: this.changeFocus.bind(this, linkman.key), | ||
})) | ||
groups.map(group => ( | ||
this.renderGroup(group) | ||
)) | ||
} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default LinkmanGroup; | ||
export default connect(state => ({ | ||
groups: state.getIn(['user', 'groups']) || [], | ||
}))(LinkmanGroup); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters