gab-social/app/javascript/gabsocial/features/groups_collection.js

65 lines
1.8 KiB
JavaScript
Raw Normal View History

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-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-04-08 02:06:59 +01:00
<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>
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
}