Skip to content
Snippets Groups Projects

Resolve "UI: Community Search when results are empty"

Merged Quoc Huy Nguyen Dinh requested to merge 123-empty-community-search into develop
5 files
+ 199
395
Compare changes
  • Side-by-side
  • Inline
Files
5
@@ -21,31 +21,26 @@ export default class CommunitiesIndex extends React.Component {
@@ -21,31 +21,26 @@ export default class CommunitiesIndex extends React.Component {
}
}
componentWillMount = () => {
componentWillMount = () => {
this.props.performSearch(
const { performSearch, username, searchQuery, searchOrder } = this.props;
this.props.username,
performSearch(username, searchQuery, searchOrder);
this.state.searchQuery,
this.state.searchOrder
);
};
};
componentDidUpdate = (prevProps, prevState) => {
if (prevProps.username !== this.props.username) {
componentDidUpdate = prevProps => {
this.props.performSearch(
const { performSearch, username, searchQuery, searchOrder } = this.props;
this.props.username,
this.state.searchQuery,
if (prevProps.username !== username) {
this.state.searchOrder
performSearch(username, searchQuery, searchOrder);
);
}
}
};
};
render() {
render() {
const {
const { communities, communities_idx, username, walletUrl, performSearch } = this.props;
communities,
const ordered =
communities_idx,
communities_idx !== null
username,
? communities_idx.map(name => {
walletUrl,
return communities.get(name);
performSearch,
})
} = this.props;
: [];
const ordered = communities_idx.map(name => communities.get(name));
const sortOptions = [
const sortOptions = [
{
{
@@ -62,31 +57,18 @@ export default class CommunitiesIndex extends React.Component {
@@ -62,31 +57,18 @@ export default class CommunitiesIndex extends React.Component {
},
},
];
];
if (communities_idx.size === 0) {
const role = comm => {
return (
return (
<center>
comm.context && comm.context.role !== 'guest' && <span className="user_role">{comm.context.role}</span>
<LoadingIndicator
style={{ marginBottom: '2rem' }}
type="circle"
/>
</center>
);
}
const role = comm =>
comm.context &&
comm.context.role !== 'guest' && (
<span className="user_role">{comm.context.role}</span>
);
);
 
};
const communityAdmins = admins => {
const communityAdmins = admins => {
if (!admins || admins.length === 0) return;
if (!admins || admins.length === 0) return null;
return (
return (
<div>
<div>
{admins.length === 1
{admins.length === 1 ? `${tt('g.administrator')}: ` : `${tt('g.administrators')}: `}
? `${tt('g.administrator')}: `
: `${tt('g.administrators')}: `}
<UserNames names={admins} />
<UserNames names={admins} />
</div>
</div>
);
);
@@ -104,9 +86,8 @@ export default class CommunitiesIndex extends React.Component {
@@ -104,9 +86,8 @@ export default class CommunitiesIndex extends React.Component {
<br />
<br />
{comm.about}
{comm.about}
<small>
<small>
{comm.subscribers} subscribers &bull;{' '}
{comm.subscribers}
{comm.num_authors} posters &bull; {comm.num_pending}{' '}
subscribers &bull; {comm.num_authors} posters &bull; {comm.num_pending} posts
posts
{admins}
{admins}
</small>
</small>
</th>
</th>
@@ -117,18 +98,14 @@ export default class CommunitiesIndex extends React.Component {
@@ -117,18 +98,14 @@ export default class CommunitiesIndex extends React.Component {
);
);
};
};
 
const { searchQuery, searchOrder } = this.state;
 
return (
return (
<PostsIndexLayout
<PostsIndexLayout category={null} enableAds={false} blogmode={false}>
category={null}
enableAds={false}
blogmode={false}
>
<div className="CommunitiesIndex c-sidebar__module">
<div className="CommunitiesIndex c-sidebar__module">
{username && (
{username && (
<div style={{ float: 'right' }}>
<div style={{ float: 'right' }}>
<a href={`${walletUrl}/@${username}/communities`}>
<a href={`${walletUrl}/@${username}/communities`}>Create a Community</a>
Create a Community
</a>
</div>
</div>
)}
)}
@@ -139,16 +116,12 @@ export default class CommunitiesIndex extends React.Component {
@@ -139,16 +116,12 @@ export default class CommunitiesIndex extends React.Component {
<div className="articles__header row">
<div className="articles__header row">
<div className="small-8 medium-7 large-8 column">
<div className="small-8 medium-7 large-8 column">
<ElasticSearchInput
<ElasticSearchInput
expanded={true}
expanded
handleSubmit={q => {
handleSubmit={q => {
this.setState({
this.setState({
searchQuery: q,
searchQuery: q,
});
});
performSearch(
performSearch(username, q, searchOrder);
username,
q,
this.state.searchOrder
);
}}
}}
redirect={false}
redirect={false}
/>
/>
@@ -156,24 +129,34 @@ export default class CommunitiesIndex extends React.Component {
@@ -156,24 +129,34 @@ export default class CommunitiesIndex extends React.Component {
<div className="small-4 medium-3 large-4 column">
<div className="small-4 medium-3 large-4 column">
<NativeSelect
<NativeSelect
options={sortOptions}
options={sortOptions}
currentlySelected={this.state.searchOrder}
currentlySelected={searchOrder}
onChange={opt => {
onChange={opt => {
this.setState({
this.setState({
searchOrder: opt.value,
searchOrder: opt.value,
});
});
performSearch(
performSearch(username, searchQuery, opt.value);
username,
this.state.searchQuery,
opt.value
);
}}
}}
/>
/>
</div>
</div>
</div>
</div>
<hr />
<hr />
<table>
{ordered.size > 0 && (
<tbody>{ordered.map(comm => row(comm.toJS()))}</tbody>
<div>
</table>
<table>
 
<tbody>
 
{ordered.map(comm => {
 
return row(comm.toJS());
 
})}
 
</tbody>
 
</table>
 
</div>
 
)}
 
{ordered.size === 0 && <div>{tt('g.community_search_no_result')}</div>}
 
{communities === null && (
 
<center>
 
<LoadingIndicator style={{ marginBottom: '2rem' }} type="circle" />
 
</center>
 
)}
</div>
</div>
</PostsIndexLayout>
</PostsIndexLayout>
);
);
@@ -195,6 +178,7 @@ module.exports = {
@@ -195,6 +178,7 @@ module.exports = {
dispatch => {
dispatch => {
return {
return {
performSearch: (observer, query, sort = 'rank') => {
performSearch: (observer, query, sort = 'rank') => {
 
console.log('search', query);
dispatch(
dispatch(
fetchDataSagaActions.listCommunities({
fetchDataSagaActions.listCommunities({
observer,
observer,
Loading