add loading message on search

This commit is contained in:
Jonathan Rainville 2018-10-16 16:16:39 -04:00 committed by Pascal Precht
parent 7ea2cb2ed6
commit 56ebd94d6d
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
1 changed files with 18 additions and 3 deletions

View File

@ -15,8 +15,17 @@ import TransactionContainer from '../containers/TransactionContainer';
import SearchBar from '../components/SearchBar';
class ExplorerLayout extends React.Component {
constructor(props) {
super(props);
this.state = {loading: false};
}
shouldComponentUpdate(nextProps) {
if (nextProps.searchResult && nextProps.searchResult !== this.props.searchResult) {
if (nextProps.searchResult && Object.keys(nextProps.searchResult).length &&
nextProps.searchResult !== this.props.searchResult) {
this.setState({loading: false});
if (nextProps.searchResult.error) {
return true;
}
@ -38,11 +47,17 @@ class ExplorerLayout extends React.Component {
return true;
}
searchTheExplorer(value) {
this.props.explorerSearch(value);
this.setState({loading: true});
}
render() {
const {explorerSearch, searchResult} = this.props;
const {searchResult} = this.props;
return (
<React.Fragment>
<SearchBar searchSubmit={searchValue => explorerSearch(searchValue)}/>
<SearchBar searchSubmit={searchValue => this.searchTheExplorer(searchValue)}/>
{this.state.loading && <p>Searching...</p>}
{searchResult.error && <Alert color="danger">{searchResult.error}</Alert>}
<Switch>
<Route exact path="/embark/explorer/accounts" component={AccountsContainer}/>