2017-02-10 03:57:35 +00:00
|
|
|
import React, { PropTypes } from 'react';
|
2016-07-18 03:59:32 +00:00
|
|
|
import { observer } from 'mobx-react';
|
2016-08-12 12:56:39 +00:00
|
|
|
import _ from 'lodash';
|
2016-08-05 15:44:15 +00:00
|
|
|
import { Flex } from 'reflexbox';
|
2016-07-19 07:30:47 +00:00
|
|
|
|
2017-05-10 07:02:11 +00:00
|
|
|
import SearchField from './components/SearchField';
|
2016-07-19 07:30:47 +00:00
|
|
|
import styles from './Search.scss';
|
|
|
|
import SearchStore from './SearchStore';
|
2016-07-18 03:59:32 +00:00
|
|
|
|
2017-05-10 07:02:11 +00:00
|
|
|
import Layout, { Title } from 'components/Layout';
|
|
|
|
import CenteredContent from 'components/CenteredContent';
|
|
|
|
import DocumentPreview from 'components/DocumentPreview';
|
|
|
|
|
2017-04-28 04:48:13 +00:00
|
|
|
@observer class Search extends React.Component {
|
2017-02-10 03:57:35 +00:00
|
|
|
static propTypes = {
|
|
|
|
route: PropTypes.object.isRequired,
|
|
|
|
routeParams: PropTypes.object.isRequired,
|
2017-04-28 04:48:13 +00:00
|
|
|
};
|
2016-07-19 07:30:47 +00:00
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.store = new SearchStore();
|
|
|
|
}
|
|
|
|
|
2017-02-10 03:57:35 +00:00
|
|
|
componentDidMount = () => {
|
|
|
|
const { splat } = this.props.routeParams;
|
|
|
|
if (this.viewNotFound) {
|
|
|
|
let searchTerm = _.last(splat.split('/'));
|
|
|
|
searchTerm = searchTerm.split(/[\s-]+/gi).join(' ');
|
|
|
|
this.store.search(searchTerm);
|
|
|
|
}
|
2017-04-28 04:48:13 +00:00
|
|
|
};
|
2017-02-10 03:57:35 +00:00
|
|
|
|
|
|
|
get viewNotFound() {
|
|
|
|
const { sceneType } = this.props.route;
|
|
|
|
return sceneType === 'notFound';
|
|
|
|
}
|
|
|
|
|
2016-07-18 03:59:32 +00:00
|
|
|
render() {
|
2017-04-28 04:48:13 +00:00
|
|
|
const search = _.debounce(searchTerm => {
|
2016-07-19 07:30:47 +00:00
|
|
|
this.store.search(searchTerm);
|
|
|
|
}, 250);
|
2016-08-22 05:21:13 +00:00
|
|
|
const title = (
|
|
|
|
<Title>
|
|
|
|
Search
|
|
|
|
</Title>
|
|
|
|
);
|
2016-07-19 07:30:47 +00:00
|
|
|
|
2016-07-18 03:59:32 +00:00
|
|
|
return (
|
|
|
|
<Layout
|
2017-04-28 04:48:13 +00:00
|
|
|
title={title}
|
2016-07-18 03:59:32 +00:00
|
|
|
titleText="Search"
|
2017-04-28 04:48:13 +00:00
|
|
|
search={false}
|
|
|
|
loading={this.store.isFetching}
|
2016-07-18 03:59:32 +00:00
|
|
|
>
|
|
|
|
<CenteredContent>
|
2017-04-28 04:48:13 +00:00
|
|
|
{this.viewNotFound &&
|
2017-02-10 03:57:35 +00:00
|
|
|
<div>
|
|
|
|
<h1>Not Found</h1>
|
|
|
|
<p>We're unable to find the page you're accessing.</p>
|
|
|
|
<hr />
|
2017-04-28 04:48:13 +00:00
|
|
|
</div>}
|
2017-02-10 03:57:35 +00:00
|
|
|
|
2016-08-05 15:44:15 +00:00
|
|
|
<Flex column auto>
|
|
|
|
<Flex auto>
|
2016-07-19 07:30:47 +00:00
|
|
|
<img
|
2017-04-28 04:48:13 +00:00
|
|
|
src={require('assets/icons/search.svg')}
|
|
|
|
className={styles.icon}
|
2016-08-05 15:44:15 +00:00
|
|
|
alt="Search"
|
2016-07-19 07:30:47 +00:00
|
|
|
/>
|
|
|
|
<SearchField
|
2017-04-28 04:48:13 +00:00
|
|
|
searchTerm={this.store.searchTerm}
|
|
|
|
onChange={search}
|
2016-07-19 07:30:47 +00:00
|
|
|
/>
|
|
|
|
</Flex>
|
2017-04-28 04:48:13 +00:00
|
|
|
{this.store.documents &&
|
|
|
|
this.store.documents.map(document => {
|
|
|
|
return (
|
|
|
|
<DocumentPreview key={document.id} document={document} />
|
|
|
|
);
|
|
|
|
})}
|
2016-07-18 03:59:32 +00:00
|
|
|
</Flex>
|
|
|
|
</CenteredContent>
|
|
|
|
</Layout>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Search;
|