2017-07-12 11:43:10 +08:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { connect } from 'react-redux'
|
2017-07-12 15:41:11 +08:00
|
|
|
import { Card, Button } from 'antd'
|
|
|
|
import { autobind } from 'core-decorators';
|
2017-07-12 11:43:10 +08:00
|
|
|
|
|
|
|
import {
|
|
|
|
fetchGroupList,
|
2017-07-17 10:17:29 +08:00
|
|
|
setCurrGroup,
|
2017-07-12 15:41:11 +08:00
|
|
|
addGroup
|
2017-07-12 11:43:10 +08:00
|
|
|
} from '../../../actions/group.js'
|
|
|
|
|
|
|
|
import './GroupList.scss'
|
|
|
|
|
|
|
|
@connect(
|
|
|
|
state => ({
|
|
|
|
groupList: state.group.groupList,
|
2017-07-12 14:18:17 +08:00
|
|
|
currGroup: state.group.currGroup
|
2017-07-12 11:43:10 +08:00
|
|
|
}),
|
|
|
|
{
|
|
|
|
fetchGroupList,
|
2017-07-17 10:17:29 +08:00
|
|
|
setCurrGroup,
|
2017-07-12 15:41:11 +08:00
|
|
|
addGroup
|
2017-07-12 11:43:10 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
export default class GroupList extends Component {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
groupList: PropTypes.array,
|
2017-07-17 10:17:29 +08:00
|
|
|
currGroup: PropTypes.object,
|
2017-07-12 16:38:42 +08:00
|
|
|
addGroup: PropTypes.func,
|
2017-07-17 10:17:29 +08:00
|
|
|
fetchGroupList: PropTypes.func,
|
|
|
|
setCurrGroup: PropTypes.func
|
2017-07-12 16:38:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillMount() {
|
2017-07-17 10:17:29 +08:00
|
|
|
this.props.fetchGroupList().then(() => {
|
|
|
|
const currGroup = this.props.groupList[0];
|
|
|
|
this.props.setCurrGroup(currGroup)
|
|
|
|
});
|
2017-07-12 15:41:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@autobind
|
|
|
|
addGroup() {
|
|
|
|
this.props.addGroup('group');
|
2017-07-12 11:43:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { groupList, currGroup } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Card title="Groups">
|
2017-07-12 15:41:11 +08:00
|
|
|
<Button type="primary" onClick={this.addGroup}>添加分组</Button>
|
2017-07-17 10:17:29 +08:00
|
|
|
<div>{currGroup.group_name}</div>
|
2017-07-12 11:43:10 +08:00
|
|
|
{
|
|
|
|
groupList.map((group, index) => (
|
2017-07-14 15:15:59 +08:00
|
|
|
<div key={index}>{group.group_name}</div>
|
2017-07-12 11:43:10 +08:00
|
|
|
))
|
|
|
|
}
|
|
|
|
</Card>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|