File size: 3,751 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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
//@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<Object>,
currentUser: ?Object,
};
class ChannelMembers extends Component<Props> {
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 (
<SectionCard data-cy="channel-members">
<SectionTitle>Members</SectionTitle>
<ListContainer>
{members &&
members.map(user => {
if (!user) return null;
return (
<UserListItemContainer key={user.id}>
<UserListItem
userObject={user}
id={user.id}
name={user.name}
username={user.username}
isCurrentUser={currentUser && user.id === currentUser.id}
profilePhoto={user.profilePhoto}
avatarSize={40}
description={user.description}
showHoverProfile={false}
messageButton={true}
/>
</UserListItemContainer>
);
})}
</ListContainer>
{channel.memberConnection &&
channel.memberConnection.pageInfo.hasNextPage && (
<ListFooter>
<FetchMoreButton
color={'brand.default'}
loading={isFetchingMore}
onClick={() => fetchMore()}
>
{isFetchingMore ? 'Loading...' : 'Load more'}
</FetchMoreButton>
</ListFooter>
)}
</SectionCard>
);
}
if (isLoading) {
return (
<SectionCard>
<Loading />
</SectionCard>
);
}
return (
<SectionCard>
<ViewError />
</SectionCard>
);
}
}
export default compose(
getChannelMembersQuery,
withCurrentUser,
viewNetworkHandler,
connect()
)(ChannelMembers);
|