2020-08-17 21:07:16 +01:00
|
|
|
import React from 'react'
|
2020-08-17 21:59:29 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2020-08-17 21:39:25 +01:00
|
|
|
import { connect } from 'react-redux'
|
2020-08-06 06:07:46 +01:00
|
|
|
import { injectIntl, defineMessages } from 'react-intl'
|
2020-08-07 23:59:39 +01:00
|
|
|
import { List as ImmutableList } from 'immutable'
|
2020-08-06 06:07:46 +01:00
|
|
|
import { me } from '../initial_state'
|
2020-08-07 23:59:39 +01:00
|
|
|
import {
|
|
|
|
clearTimeline,
|
|
|
|
expandGroupCollectionTimeline,
|
|
|
|
} from '../actions/timelines'
|
|
|
|
import {
|
|
|
|
setGroupTimelineSort,
|
|
|
|
} from '../actions/groups'
|
|
|
|
import {
|
2021-01-14 03:49:00 +00:00
|
|
|
MIN_UNAUTHENTICATED_PAGES,
|
2020-08-11 04:16:08 +01:00
|
|
|
GROUP_TIMELINE_SORTING_TYPE_HOT,
|
2020-08-07 23:59:39 +01:00
|
|
|
GROUP_TIMELINE_SORTING_TYPE_NEWEST,
|
|
|
|
} from '../constants'
|
|
|
|
import getSortBy from '../utils/group_sort_by'
|
|
|
|
import Text from '../components/text'
|
2020-08-06 06:07:46 +01:00
|
|
|
import StatusList from '../components/status_list'
|
2020-08-07 05:19:18 +01:00
|
|
|
import GroupSortBlock from '../components/group_sort_block'
|
2020-08-07 23:59:39 +01:00
|
|
|
import GroupsCollection from './groups_collection'
|
2020-08-06 06:07:46 +01:00
|
|
|
|
2020-08-17 21:07:16 +01:00
|
|
|
class GroupCollectionTimeline extends React.PureComponent {
|
2020-08-06 06:07:46 +01:00
|
|
|
|
2020-08-07 23:59:39 +01:00
|
|
|
state = {
|
2021-01-24 20:21:09 +00:00
|
|
|
//keep track of page loads for if no user,
|
2021-01-14 03:49:00 +00:00
|
|
|
//only allow MIN_UNAUTHENTICATED_PAGES page loads before showing sign up msg
|
2020-12-24 18:34:14 +00:00
|
|
|
page: 1,
|
2020-08-07 23:59:39 +01:00
|
|
|
}
|
|
|
|
|
2020-08-06 06:07:46 +01:00
|
|
|
componentDidMount() {
|
2020-08-07 05:19:18 +01:00
|
|
|
const {
|
|
|
|
collectionType,
|
|
|
|
sortByValue,
|
|
|
|
sortByTopValue,
|
|
|
|
} = this.props
|
2020-08-06 06:07:46 +01:00
|
|
|
|
2020-08-11 04:16:08 +01:00
|
|
|
if (this.props.collectionType === 'featured' && sortByValue !== GROUP_TIMELINE_SORTING_TYPE_HOT) {
|
2020-08-07 23:59:39 +01:00
|
|
|
this.props.setFeaturedTop()
|
2021-02-05 05:12:51 +00:00
|
|
|
} else if (!!me && this.props.collectionType === 'member' && sortByValue !== GROUP_TIMELINE_SORTING_TYPE_NEWEST) {
|
|
|
|
this.props.setMemberNewest()
|
2020-08-07 23:59:39 +01:00
|
|
|
} else {
|
|
|
|
const sortBy = getSortBy(sortByValue, sortByTopValue)
|
|
|
|
this.props.onExpandGroupCollectionTimeline(collectionType, { sortBy })
|
2020-08-06 06:07:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-07 05:19:18 +01:00
|
|
|
componentDidUpdate(prevProps) {
|
2021-01-24 20:21:09 +00:00
|
|
|
if (prevProps.sortByValue !== this.props.sortByValue ||
|
2020-08-07 23:59:39 +01:00
|
|
|
prevProps.sortByTopValue !== this.props.sortByTopValue ||
|
|
|
|
prevProps.collectionType !== this.props.collectionType) {
|
|
|
|
this.props.onClearTimeline(`group_collection:${prevProps.collectionType}`)
|
|
|
|
this.handleLoadMore()
|
2020-08-07 05:19:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-06 06:07:46 +01:00
|
|
|
handleLoadMore = (maxId) => {
|
2020-08-07 05:19:18 +01:00
|
|
|
const {
|
|
|
|
collectionType,
|
|
|
|
sortByValue,
|
|
|
|
sortByTopValue,
|
|
|
|
} = this.props
|
2020-12-24 18:34:14 +00:00
|
|
|
const { page } = this.state
|
2021-01-24 20:21:09 +00:00
|
|
|
|
2020-12-24 18:34:14 +00:00
|
|
|
const newPage = !!maxId ? this.state.page + 1 : 1
|
2021-01-14 03:49:00 +00:00
|
|
|
if (!!maxId && !me && page >= MIN_UNAUTHENTICATED_PAGES) return false
|
2020-12-24 18:34:14 +00:00
|
|
|
this.setState({ page: newPage })
|
2020-08-07 05:19:18 +01:00
|
|
|
|
2020-08-07 23:59:39 +01:00
|
|
|
const sortBy = getSortBy(sortByValue, sortByTopValue)
|
2020-12-24 18:34:14 +00:00
|
|
|
const options = { sortBy, maxId, page: newPage }
|
2020-08-07 05:19:18 +01:00
|
|
|
|
2020-08-07 23:59:39 +01:00
|
|
|
this.props.onExpandGroupCollectionTimeline(collectionType, options)
|
2020-08-06 06:07:46 +01:00
|
|
|
}
|
2021-01-24 20:21:09 +00:00
|
|
|
|
2020-08-06 06:07:46 +01:00
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
collectionType,
|
|
|
|
intl,
|
2020-08-08 00:18:56 +01:00
|
|
|
hasNoGroupMembers,
|
2020-08-06 06:07:46 +01:00
|
|
|
} = this.props
|
2020-12-24 18:34:14 +00:00
|
|
|
const { page } = this.state
|
2020-08-06 06:07:46 +01:00
|
|
|
|
2020-08-08 00:18:56 +01:00
|
|
|
const emptyMessage = !!me && collectionType === 'member' && hasNoGroupMembers ? (
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.w100PC]}>
|
|
|
|
<Text className={[_s.d, _s.mb10].join(' ')}>
|
2020-08-07 23:59:39 +01:00
|
|
|
Join some groups then come back here to view your group timeline
|
|
|
|
</Text>
|
|
|
|
<GroupsCollection activeTab='featured' />
|
|
|
|
</div>
|
|
|
|
) : intl.formatMessage(messages.empty)
|
|
|
|
|
2021-01-14 03:49:00 +00:00
|
|
|
const canLoadMore = page < MIN_UNAUTHENTICATED_PAGES && !me || !!me
|
2020-09-14 23:19:24 +01:00
|
|
|
|
2020-08-06 06:07:46 +01:00
|
|
|
return (
|
2020-08-17 21:07:16 +01:00
|
|
|
<React.Fragment>
|
2020-08-08 00:18:56 +01:00
|
|
|
<GroupSortBlock collectionType={collectionType} />
|
2020-08-07 05:19:18 +01:00
|
|
|
<StatusList
|
|
|
|
scrollKey={`group-collection-timeline-${collectionType}`}
|
2020-08-07 23:59:39 +01:00
|
|
|
timelineId={`group_collection:${collectionType}`}
|
2020-09-14 23:19:24 +01:00
|
|
|
onLoadMore={canLoadMore ? this.handleLoadMore : undefined}
|
2020-08-07 23:59:39 +01:00
|
|
|
emptyMessage={emptyMessage}
|
2020-08-07 05:19:18 +01:00
|
|
|
/>
|
2020-08-17 21:07:16 +01:00
|
|
|
</React.Fragment>
|
2020-08-06 06:07:46 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-08-19 01:22:15 +01:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
empty: { id: 'empty_column.group_collection_timeline', defaultMessage: 'There are no gabs to display.' },
|
|
|
|
})
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => {
|
|
|
|
|
|
|
|
let hasNoGroupMembers = true
|
|
|
|
try {
|
|
|
|
hasNoGroupMembers = state.getIn(['group_lists', 'member', 'items'], ImmutableList()).count() === 0
|
|
|
|
} catch (error) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
hasNoGroupMembers,
|
|
|
|
sortByValue: state.getIn(['group_lists', 'sortByValue']),
|
|
|
|
sortByTopValue: state.getIn(['group_lists', 'sortByTopValue']),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
onClearTimeline(timeline) {
|
|
|
|
dispatch(clearTimeline(timeline))
|
|
|
|
},
|
|
|
|
onExpandGroupCollectionTimeline(collectionType, options) {
|
|
|
|
dispatch(expandGroupCollectionTimeline(collectionType, options))
|
|
|
|
},
|
|
|
|
setFeaturedTop() {
|
|
|
|
dispatch(setGroupTimelineSort(GROUP_TIMELINE_SORTING_TYPE_HOT))
|
|
|
|
},
|
|
|
|
setMemberNewest() {
|
|
|
|
dispatch(setGroupTimelineSort(GROUP_TIMELINE_SORTING_TYPE_NEWEST))
|
|
|
|
},
|
2021-01-24 20:21:09 +00:00
|
|
|
setMemberHot() {
|
|
|
|
dispatch(setGroupTimelineSort(GROUP_TIMELINE_SORTING_TYPE_HOT))
|
|
|
|
},
|
2020-08-19 01:22:15 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
GroupCollectionTimeline.propTypes = {
|
|
|
|
params: PropTypes.object.isRequired,
|
|
|
|
onClearTimeline: PropTypes.func.isRequired,
|
|
|
|
onExpandGroupCollectionTimeline: PropTypes.func.isRequired,
|
|
|
|
setFeaturedTop: PropTypes.func.isRequired,
|
|
|
|
setMemberNewest: PropTypes.func.isRequired,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
collectionType: PropTypes.string.isRequired,
|
|
|
|
sortByValue: PropTypes.string.isRequired,
|
|
|
|
sortByTopValue: PropTypes.string,
|
|
|
|
hasStatuses: PropTypes.bool.isRequired,
|
|
|
|
}
|
|
|
|
|
2021-01-24 20:21:09 +00:00
|
|
|
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(GroupCollectionTimeline))
|