import React from 'react' import PropTypes from 'prop-types' import { connect } from 'react-redux' import { injectIntl, defineMessages } from 'react-intl' import { List as ImmutableList } from 'immutable' import { me } from '../initial_state' import { clearTimeline, expandGroupCollectionTimeline, } from '../actions/timelines' import { setGroupTimelineSort, } from '../actions/groups' import { GROUP_TIMELINE_SORTING_TYPE_HOT, GROUP_TIMELINE_SORTING_TYPE_NEWEST, } from '../constants' import getSortBy from '../utils/group_sort_by' import Text from '../components/text' import StatusList from '../components/status_list' import GroupSortBlock from '../components/group_sort_block' import GroupsCollection from './groups_collection' class GroupCollectionTimeline extends React.PureComponent { state = { //keep track of loads for if no user, //only allow 2 loads before showing sign up msg loadCount: 0, } componentDidMount() { const { collectionType, sortByValue, sortByTopValue, } = this.props if (this.props.collectionType === 'featured' && sortByValue !== GROUP_TIMELINE_SORTING_TYPE_HOT) { 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 }) } } componentDidUpdate(prevProps) { if (prevProps.sortByValue !== this.props.sortByValue || prevProps.sortByTopValue !== this.props.sortByTopValue || prevProps.collectionType !== this.props.collectionType) { this.props.onClearTimeline(`group_collection:${prevProps.collectionType}`) this.handleLoadMore() } } handleLoadMore = (maxId) => { const { collectionType, sortByValue, sortByTopValue, } = this.props const { loadCount } = this.state if (!!maxId && !me) { this.setState({ loadCount: this.state.loadCount + 1 }) if (loadCount >= 2) return false } else if (!maxId && loadCount !== 0) { this.setState({ loadCount: 0 }) } const sortBy = getSortBy(sortByValue, sortByTopValue) const options = { sortBy, maxId } this.props.onExpandGroupCollectionTimeline(collectionType, options) } render() { const { collectionType, intl, hasNoGroupMembers, } = this.props const { loadCount } = this.state const emptyMessage = !!me && collectionType === 'member' && hasNoGroupMembers ? (