//@flow import * as React from 'react'; import { connect } from 'react-redux'; import { withRouter } from 'react-router'; import compose from 'recompose/compose'; import { CommunityListItem } from 'src/components/entities'; import { ErrorBoundary } from 'src/components/error'; import { Loading } from 'src/components/loading'; import { PrimaryOutlineButton } from 'src/components/button'; import { getUserCommunityConnection } from 'shared/graphql/queries/user/getUserCommunityConnection'; import type { GetUserCommunityConnectionType } from 'shared/graphql/queries/user/getUserCommunityConnection'; type Props = { data: { user: GetUserCommunityConnectionType, }, currentUser: Object, user: Object, }; class CommunityList extends React.Component { render() { const { data } = this.props; if (data.loading) { return ; } if ( !data.user || !data.user.communityConnection || !data.user.communityConnection.edges || data.user.communityConnection.edges.length === 0 ) { return (
Explore communities
); } const communities = data.user.communityConnection.edges.map( c => c && c.node ); let sortedCommunities = communities; if (sortedCommunities[0] && sortedCommunities[0].contextPermissions) { sortedCommunities = communities.slice(); } return (
{sortedCommunities.map(community => { if (!community) return null; return ( ); })}
); } } export default compose( withRouter, getUserCommunityConnection, connect() )(CommunityList);