Skip to content
Snippets Groups Projects
Commit 7a947659 authored by Quoc Huy Nguyen Dinh's avatar Quoc Huy Nguyen Dinh
Browse files

Search page should not show an error by default

parent a9ec8c24
No related branches found
No related tags found
2 merge requests!239- fix search results not appearing,!230Fix search results not showing
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import tt from 'counterpart'; import _ from 'lodash';
import { search } from 'app/redux/SearchReducer'; import { search } from 'app/redux/SearchReducer';
import Callout from 'app/components/elements/Callout'; import Callout from 'app/components/elements/Callout';
import ElasticSearchInput from 'app/components/elements/ElasticSearchInput'; import ElasticSearchInput from 'app/components/elements/ElasticSearchInput';
import PostsList from 'app/components/cards/PostsList'; import PostsList from 'app/components/cards/PostsList';
import { List, Map, fromJS } from 'immutable'; import { fromJS } from 'immutable';
class SearchIndex extends React.Component { class SearchIndex extends React.Component {
static propTypes = { static propTypes = {
...@@ -68,6 +68,7 @@ class SearchIndex extends React.Component { ...@@ -68,6 +68,7 @@ class SearchIndex extends React.Component {
render() { render() {
const { result, loading, params, performSearch, error } = this.props; const { result, loading, params, performSearch, error } = this.props;
const errorMessage = _.get(error, 'message', undefined);
const searchResults = ( const searchResults = (
<PostsList ref="list" posts={fromJS(result)} loading={loading} loadMore={this.fetchMoreResults} /> <PostsList ref="list" posts={fromJS(result)} loading={loading} loadMore={this.fetchMoreResults} />
...@@ -89,11 +90,15 @@ class SearchIndex extends React.Component { ...@@ -89,11 +90,15 @@ class SearchIndex extends React.Component {
/> />
</div> </div>
</div> </div>
{!loading && !error && result.length === 0 ? <Callout>Nothing was found.</Callout> : searchResults} {!loading && !errorMessage && result.length === 0 ? (
<Callout>Nothing was found.</Callout>
) : (
searchResults
)}
{!loading && {!loading &&
error && ( errorMessage && (
<Callout title="There was an error" type="alert"> <Callout title="There was an error" type="alert">
{error.message} {errorMessage}
</Callout> </Callout>
)} )}
</article> </article>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment