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'
|
|
|
|
import { connectGroupCollectionStream } from '../actions/streaming'
|
2020-08-07 23:59:39 +01:00
|
|
|
import {
|
|
|
|
clearTimeline,
|
|
|
|
expandGroupCollectionTimeline,
|
|
|
|
} from '../actions/timelines'
|
|
|
|
import {
|
|
|
|
setGroupTimelineSort,
|
|
|
|
} from '../actions/groups'
|
|
|
|
import {
|
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 = {
|
|
|
|
//keep track of loads for if no user,
|
|
|
|
//only allow 2 loads before showing sign up msg
|
|
|
|
loadCount: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
_unsubscribe() {
|
|
|
|
if (this.disconnect && !!me) {
|
|
|
|
this.disconnect()
|
|
|
|
this.disconnect = null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_subscribe = () => {
|
|
|
|
if (!!me) {
|
|
|
|
const {
|
|
|
|
collectionType,
|
|
|
|
sortByValue,
|
|
|
|
sortByTopValue,
|
|
|
|
} = this.props
|
|
|
|
|
|
|
|
if (collectionType === 'member' && sortByValue === 'new') {
|
|
|
|
const sortBy = getSortBy(sortByValue, sortByTopValue)
|
|
|
|
this.disconnect = this.props.onConnectGroupCollectionStream(collectionType, sortBy)
|
|
|
|
}
|
|
|
|
}
|
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()
|
|
|
|
} else if (!!me && this.props.collectionType === 'member' && sortByValue !== GROUP_TIMELINE_SORTING_TYPE_NEWEST) {
|
|
|
|
this.props.setMemberNewest()
|
|
|
|
} else {
|
|
|
|
const sortBy = getSortBy(sortByValue, sortByTopValue)
|
|
|
|
this.props.onExpandGroupCollectionTimeline(collectionType, { sortBy })
|
2020-08-06 06:07:46 +01:00
|
|
|
|
2020-08-07 23:59:39 +01:00
|
|
|
this._subscribe()
|
2020-08-06 06:07:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-07 05:19:18 +01:00
|
|
|
componentDidUpdate(prevProps) {
|
2020-08-07 23:59:39 +01:00
|
|
|
if (prevProps.sortByValue !== this.props.sortByValue ||
|
|
|
|
prevProps.sortByTopValue !== this.props.sortByTopValue ||
|
|
|
|
prevProps.collectionType !== this.props.collectionType) {
|
|
|
|
this._unsubscribe()
|
|
|
|
this._subscribe()
|
|
|
|
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
|
|
|
componentWillUnmount() {
|
2020-08-07 23:59:39 +01:00
|
|
|
this._unsubscribe()
|
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-08-07 23:59:39 +01:00
|
|
|
const sortBy = getSortBy(sortByValue, sortByTopValue)
|
2020-08-07 05:19:18 +01:00
|
|
|
const options = { sortBy, maxId }
|
|
|
|
|
2020-08-07 23:59:39 +01:00
|
|
|
this.props.onExpandGroupCollectionTimeline(collectionType, options)
|
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-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)
|
|
|
|
|
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-08-07 05:19:18 +01:00
|
|
|
onLoadMore={this.handleLoadMore}
|
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) => ({
|
|
|
|
onConnectGroupCollectionStream(collectionType, sortBy) {
|
|
|
|
dispatch(connectGroupCollectionStream(collectionType, sortBy))
|
|
|
|
},
|
|
|
|
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))
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
GroupCollectionTimeline.propTypes = {
|
|
|
|
params: PropTypes.object.isRequired,
|
|
|
|
onConnectGroupCollectionStream: PropTypes.func.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,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(GroupCollectionTimeline))
|