//@flow import React, { Component } from 'react'; import { connect } from 'react-redux'; import compose from 'recompose/compose'; import { Loading } from 'src/components/loading'; import getChannelMembersQuery from 'shared/graphql/queries/channel/getChannelMemberConnection'; import type { GetChannelMemberConnectionType } from 'shared/graphql/queries/channel/getChannelMemberConnection'; import { FetchMoreButton } from 'src/components/threadFeed/style'; import ViewError from 'src/components/viewError'; import viewNetworkHandler from 'src/components/viewNetworkHandler'; import { UserListItem } from 'src/components/entities'; import { SectionCard, SectionTitle } from 'src/components/settingsViews/style'; import { UserListItemContainer } from '../style'; import { ListContainer, ListFooter } from 'src/components/listItems/style'; import type { Dispatch } from 'redux'; import { withCurrentUser } from 'src/components/withCurrentUser'; type Props = { data: { channel: GetChannelMemberConnectionType, fetchMore: Function, }, isLoading: boolean, isFetchingMore: boolean, dispatch: Dispatch, currentUser: ?Object, }; class ChannelMembers extends Component { shouldComponentUpdate(nextProps: Props) { const curr = this.props; if (curr.data.channel && nextProps.data.channel && !curr.isFetchingMore) { if ( curr.data.channel.memberConnection && nextProps.data.channel.memberConnection && curr.data.channel.memberConnection.edges.length === nextProps.data.channel.memberConnection.edges.length ) { return false; } } return true; } render() { const { data: { channel, fetchMore }, data, isLoading, isFetchingMore, currentUser, } = this.props; if (data && data.channel) { const members = channel.memberConnection && channel.memberConnection.edges.map(member => member && member.node); return ( Members {members && members.map(user => { if (!user) return null; return ( ); })} {channel.memberConnection && channel.memberConnection.pageInfo.hasNextPage && ( fetchMore()} > {isFetchingMore ? 'Loading...' : 'Load more'} )} ); } if (isLoading) { return ( ); } return ( ); } } export default compose( getChannelMembersQuery, withCurrentUser, viewNetworkHandler, connect() )(ChannelMembers);