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

91 lines
2.9 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'
import { FormattedMessage } from 'react-intl'
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, 'items']),
isFetched: state.getIn(['group_lists', activeTab, 'isFetched']),
isLoading: state.getIn(['group_lists', activeTab, 'isLoading']),
2020-02-22 23:26:23 +00:00
})
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,
isFetched: PropTypes.bool.isRequired,
isLoading: PropTypes.bool.isRequired,
2020-02-22 23:26:23 +00: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 23:26:23 +00:00
if (isLoading && groupIds.size === 0) {
2020-04-02 04:17:21 +01: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-02 04:17:21 +01:00
}
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
}