File size: 3,101 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
// @flow
import * as React from 'react';
import compose from 'recompose/compose';
import { connect } from 'react-redux';
import { deduplicateChildren } from 'src/components/infiniteScroll/deduplicateChildren';
import { withRouter } from 'react-router';
import getChannelMembersQuery, {
type GetChannelMemberConnectionType,
} from 'shared/graphql/queries/channel/getChannelMemberConnection';
import { Card } from 'src/components/card';
import { Loading } from 'src/components/loading';
import NextPageButton from 'src/components/nextPageButton';
import viewNetworkHandler from 'src/components/viewNetworkHandler';
import ViewError from 'src/components/viewError';
import { UserListItem } from 'src/components/entities';
import type { Dispatch } from 'redux';
import { withCurrentUser } from 'src/components/withCurrentUser';
type Props = {
data: {
channel: GetChannelMemberConnectionType,
fetchMore: Function,
networkStatus: number,
},
dispatch: Dispatch<Object>,
isLoading: boolean,
isFetchingMore: boolean,
history: Object,
currentUser: ?Object,
};
class MembersList extends React.Component<Props> {
shouldComponentUpdate(nextProps) {
const curr = this.props;
// fetching more
if (curr.data.networkStatus === 7 && nextProps.data.networkStatus === 3)
return false;
return true;
}
render() {
const {
data: { channel },
isLoading,
currentUser,
isFetchingMore,
} = this.props;
if (channel && channel.memberConnection) {
const { edges: members, pageInfo } = channel.memberConnection;
const nodes = members.map(member => member && member.node);
const uniqueNodes = deduplicateChildren(nodes, 'id');
const { hasNextPage } = pageInfo;
return (
<React.Fragment>
{uniqueNodes.map(user => {
if (!user) return null;
return (
<UserListItem
key={user.id}
userObject={user}
name={user.name}
username={user.username}
description={user.description}
profilePhoto={user.profilePhoto}
isCurrentUser={currentUser && user.id === currentUser.id}
avatarSize={40}
showHoverProfile={false}
messageButton={currentUser && user.id !== currentUser.id}
/>
);
})}
{hasNextPage && (
<NextPageButton
isFetchingMore={isFetchingMore}
fetchMore={this.props.data.fetchMore}
bottomOffset={-100}
>
Load more members
</NextPageButton>
)}
</React.Fragment>
);
}
if (isLoading) {
return <Loading />;
}
return (
<Card>
<ViewError
refresh
heading={'We weren’t able to fetch the members of this community.'}
/>
</Card>
);
}
}
export default compose(
withRouter,
withCurrentUser,
getChannelMembersQuery,
viewNetworkHandler,
connect()
)(MembersList);
|