2020-02-22 23:26:23 +00:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
2020-03-04 22:26:01 +00:00
|
|
|
import { fetchGroups } from '../actions/groups'
|
2020-05-07 05:03:34 +01:00
|
|
|
import { BREAKPOINT_EXTRA_SMALL } from '../constants'
|
|
|
|
import Responsive from './ui/util/responsive_component'
|
2020-04-02 04:17:21 +01:00
|
|
|
import ColumnIndicator from '../components/column_indicator'
|
2020-03-25 03:08:43 +00:00
|
|
|
import ScrollableList from '../components/scrollable_list'
|
2020-03-04 22:26:01 +00:00
|
|
|
import GroupCollectionItem from '../components/group_collection_item'
|
2020-02-22 23:26:23 +00:00
|
|
|
|
|
|
|
const mapStateToProps = (state, { activeTab }) => ({
|
|
|
|
groupIds: state.getIn(['group_lists', activeTab]),
|
|
|
|
})
|
|
|
|
|
2020-02-25 16:04:44 +00:00
|
|
|
export default
|
|
|
|
@connect(mapStateToProps)
|
2020-02-22 23:26:23 +00:00
|
|
|
class GroupsCollection extends ImmutablePureComponent {
|
2020-04-08 02:06:59 +01:00
|
|
|
|
2020-02-22 23:26:23 +00:00
|
|
|
static propTypes = {
|
|
|
|
activeTab: PropTypes.string.isRequired,
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
|
|
|
groupIds: ImmutablePropTypes.list,
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillMount() {
|
|
|
|
this.props.dispatch(fetchGroups(this.props.activeTab))
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate(oldProps) {
|
|
|
|
if (this.props.activeTab && this.props.activeTab !== oldProps.activeTab) {
|
|
|
|
this.props.dispatch(fetchGroups(this.props.activeTab))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { groupIds } = this.props
|
|
|
|
|
2020-04-02 04:17:21 +01:00
|
|
|
if (!groupIds) {
|
|
|
|
return <ColumnIndicator type='loading' />
|
|
|
|
}
|
2020-03-27 15:29:52 +00:00
|
|
|
|
2020-04-08 02:06:59 +01:00
|
|
|
const halfCount = parseInt(groupIds.size / 2)
|
|
|
|
|
2020-02-22 23:26:23 +00:00
|
|
|
return (
|
|
|
|
<div className={[_s.default, _s.flexRow, _s.flexWrap].join(' ')}>
|
2020-05-07 05:03:34 +01:00
|
|
|
<Responsive max={BREAKPOINT_EXTRA_SMALL}>
|
|
|
|
<div className={[_s.default, _s.width100PC, _s.px5].join(' ')}>
|
|
|
|
<ScrollableList scrollKey='group-collection-column-1'>
|
|
|
|
{
|
|
|
|
groupIds.map((groupId, i) => (
|
|
|
|
<GroupCollectionItem key={`group-collection-item-${i}`} id={groupId} />
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</ScrollableList>
|
|
|
|
</div>
|
|
|
|
</Responsive>
|
|
|
|
<Responsive min={BREAKPOINT_EXTRA_SMALL}>
|
|
|
|
<div className={[_s.default, _s.flexNormal].join(' ')}>
|
|
|
|
<ScrollableList scrollKey='group-collection-column-1'>
|
|
|
|
{
|
|
|
|
groupIds.slice(0, halfCount).map((groupId, i) => (
|
|
|
|
<GroupCollectionItem key={`group-collection-item-${i}`} id={groupId} />
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</ScrollableList>
|
|
|
|
</div>
|
|
|
|
<div className={[_s.default, _s.flexNormal].join(' ')}>
|
|
|
|
<ScrollableList scrollKey='group-collection-column-2'>
|
|
|
|
{
|
|
|
|
groupIds.slice(halfCount, groupIds.size).map((groupId, i) => (
|
|
|
|
<GroupCollectionItem key={`group-collection-item-${i}`} id={groupId} />
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</ScrollableList>
|
|
|
|
</div>
|
|
|
|
</Responsive>
|
2020-02-22 23:26:23 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2020-04-08 02:06:59 +01:00
|
|
|
|
2020-02-22 23:26:23 +00:00
|
|
|
}
|