import ImmutablePropTypes from 'react-immutable-proptypes' import ImmutablePureComponent from 'react-immutable-pure-component' import { injectIntl, defineMessages } from 'react-intl' import { fetchGroups } from '../actions/groups' import Block from '../components/block' import Button from '../components/button' import ColumnIndicator from '../components/column_indicator' import Heading from '../components/heading' import GroupListItem from '../components/group_list_item' import Input from '../components/input' const messages = defineMessages({ empty: { id: 'groups.empty', defaultMessage: 'There are no groups to display' }, featured: { id: 'featured', defaultMessage: 'Featured' }, new: { id: 'new', defaultMessage: 'Just Added' }, member: { id: 'my_groups', defaultMessage: 'My Groups' }, admin: { id: 'admin', defaultMessage: 'Admin' }, }) 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']), }) export default @injectIntl @connect(mapStateToProps) class GroupsCollection extends ImmutablePureComponent { static propTypes = { activeTab: PropTypes.string.isRequired, dispatch: PropTypes.func.isRequired, groupIds: ImmutablePropTypes.list, intl: PropTypes.object.isRequired, isFetched: PropTypes.bool.isRequired, isLoading: PropTypes.bool.isRequired, } state = { isSearchVisible: false, searchText: '', } componentWillMount() { this.props.dispatch(fetchGroups(this.props.activeTab)) } componentDidUpdate(oldProps) { if (this.props.activeTab && this.props.activeTab !== oldProps.activeTab) { this.setState({ isSearchVisible: false, searchText: '', }) this.props.dispatch(fetchGroups(this.props.activeTab)) } } handleToggleSearch = () => { this.setState({ isSearchVisible: !this.state.isSearchVisible }) } handleOnChangeSearch = (value) => { this.setState({ searchText: value }) } render() { const { activeTab, groupIds, intl, isLoading, isFetched, } = this.props const { isSearchVisible, searchText, } = this.state if (isLoading && groupIds.size === 0) { return } else if (isFetched && groupIds.size === 0) { return } const isAddable = ['featured', 'new'].indexOf(activeTab) > -1 return (
{intl.formatMessage(messages[activeTab])}
{ /*
{ isSearchVisible &&
}
{ groupIds.map((groupId, i) => ( )) }
) } }