From a7493af979f22bfb32a8aec5db020d108efcb655 Mon Sep 17 00:00:00 2001 From: gaba Date: Tue, 11 Apr 2017 11:58:19 -0700 Subject: [PATCH] Fix search box in Community Admin. --- .../Community/CommunityContainer.js | 20 ++++++++---- .../src/containers/Community/People.js | 32 ++++++++----------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/client/coral-admin/src/containers/Community/CommunityContainer.js b/client/coral-admin/src/containers/Community/CommunityContainer.js index 4f65303ff..ecee9336c 100644 --- a/client/coral-admin/src/containers/Community/CommunityContainer.js +++ b/client/coral-admin/src/containers/Community/CommunityContainer.js @@ -28,11 +28,12 @@ class CommunityContainer extends Component { super(props); this.state = { - searchValue: '' + searchValue: '', + timer: null }; this.onKeyDownHandler = this.onKeyDownHandler.bind(this); - this.onChangeHandler = this.onChangeHandler.bind(this); + this.onSearchChange = this.onSearchChange.bind(this); this.onHeaderClickHandler = this.onHeaderClickHandler.bind(this); this.onNewPageHandler = this.onNewPageHandler.bind(this); } @@ -48,9 +49,16 @@ class CommunityContainer extends Component { } } - onChangeHandler(e) { - this.setState({ - searchValue: e.target.value + onSearchChange(e) { + const value = e.target.value; + this.setState((prevState) => { + prevState.searchValue = value; + clearTimeout(prevState.timer); + const fetchAccounts = this.props.fetchAccounts; + prevState.timer = setTimeout(() => { + fetchAccounts({value}); + }, 350); + return prevState; }); } @@ -86,11 +94,11 @@ class CommunityContainer extends Component { isFetching={community.isFetchingPeople} commenters={community.accounts} searchValue={searchValue} + onSearchChange={this.onSearchChange} error={community.errorPeople} totalPages={community.totalPagesPeople} page={community.pagePeople} onKeyDown={this.onKeyDownHandler} - onChange={this.onChangeHandler} onHeaderClickHandler={this.onHeaderClickHandler} onNewPageHandler={this.onNewPageHandler} /> diff --git a/client/coral-admin/src/containers/Community/People.js b/client/coral-admin/src/containers/Community/People.js index b5701b5a4..0011cd704 100644 --- a/client/coral-admin/src/containers/Community/People.js +++ b/client/coral-admin/src/containers/Community/People.js @@ -5,7 +5,7 @@ import translations from 'coral-admin/src/translations.json'; import styles from './Community.css'; import Table from './Table'; import Loading from './Loading'; -import {Pager} from 'coral-ui'; +import {Pager, Icon} from 'coral-ui'; import EmptyCard from '../../components/EmptyCard'; const lang = new I18n(translations); @@ -29,28 +29,22 @@ const tableHeaders = [ } ]; -const People = ({isFetching, commenters, ...props}) => { +const People = ({isFetching, commenters, searchValue, onSearchChange, ...props}) => { const hasResults = !isFetching && !!commenters.length; return (
-
-
- -
- -
-
-
+
+ + +
{ isFetching && }