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

91 lines
2.9 KiB
JavaScript
Raw Normal View History

2020-02-22 18:26:23 -05:00
import ImmutablePropTypes from 'react-immutable-proptypes'
import ImmutablePureComponent from 'react-immutable-pure-component'
import { FormattedMessage } from 'react-intl'
2020-03-04 17:26:01 -05:00
import { fetchGroups } from '../actions/groups'
2020-05-07 00:03:34 -04:00
import { BREAKPOINT_EXTRA_SMALL } from '../constants'
import Responsive from './ui/util/responsive_component'
2020-04-01 23:17:21 -04:00
import ColumnIndicator from '../components/column_indicator'
2020-03-24 23:08:43 -04:00
import ScrollableList from '../components/scrollable_list'
2020-03-04 17:26:01 -05:00
import GroupCollectionItem from '../components/group_collection_item'
2020-02-22 18:26:23 -05:00
const mapStateToProps = (state, { activeTab }) => ({
groupIds: state.getIn(['group_lists', activeTab, 'items']),
isFetched: state.getIn(['group_lists', activeTab, 'isFetched']),
isLoading: state.getIn(['group_lists', activeTab, 'isLoading']),
2020-02-22 18:26:23 -05:00
})
2020-02-25 11:04:44 -05:00
export default
@connect(mapStateToProps)
2020-02-22 18:26:23 -05:00
class GroupsCollection extends ImmutablePureComponent {
2020-04-07 21:06:59 -04:00
2020-02-22 18:26:23 -05:00
static propTypes = {
activeTab: PropTypes.string.isRequired,
dispatch: PropTypes.func.isRequired,
groupIds: ImmutablePropTypes.list,
isFetched: PropTypes.bool.isRequired,
isLoading: PropTypes.bool.isRequired,
2020-02-22 18:26:23 -05:00
}
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,
isLoading,
isFetched,
} = this.props
2020-02-22 18:26:23 -05:00
if (isLoading && groupIds.size === 0) {
2020-04-01 23:17:21 -04:00
return <ColumnIndicator type='loading' />
} else if (isFetched && groupIds.size === 0) {
return <ColumnIndicator type='error' message={<FormattedMessage id='groups.empty' defaultMessage='There are no groups to display' />} />
2020-04-01 23:17:21 -04:00
}
2020-03-27 11:29:52 -04:00
2020-04-07 21:06:59 -04:00
const halfCount = parseInt(groupIds.size / 2)
2020-02-22 18:26:23 -05:00
return (
<div className={[_s.default, _s.flexRow, _s.flexWrap].join(' ')}>
2020-05-07 00:03:34 -04: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 18:26:23 -05:00
</div>
)
}
2020-04-07 21:06:59 -04:00
2020-02-22 18:26:23 -05:00
}