| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- import React from 'react';
- import Page from '../PageList/Page';
- import SearchResultList from './SearchResultList';
- // Search.SearchResult
- export default class SearchResult extends React.Component {
- isNotSearchedYet() {
- return !this.props.searchResultMeta.took;
- }
- isNotFound() {
- return this.props.searchingKeyword !== '' && this.props.pages.length === 0;
- }
- isError() {
- if (this.props.searchError !== null) {
- return true;
- }
- return false;
- }
- render() {
- const excludePathString = this.props.tree;
- //console.log(this.props.searchError);
- //console.log(this.isError());
- if (this.isError()) {
- return (
- <div className="content-main">
- <i className="searcing fa fa-warning"></i> Error on searching.
- </div>
- );
- }
- if (this.isNotSearchedYet()) {
- return <div />;
- }
- if (this.isNotFound()) {
- let under = '';
- if (this.props.tree !== '') {
- under = ` under "${this.props.tree}"`;
- }
- return (
- <div className="content-main">
- <i className="fa fa-meh-o" /> No page found with "{this.props.searchingKeyword}"{under}
- </div>
- );
- }
- const listView = this.props.pages.map((page) => {
- const pageId = "#" + page._id;
- return (
- <Page page={page}
- linkTo={pageId}
- key={page._id}
- excludePathString={excludePathString}
- >
- <div className="page-list-option">
- <a href={page.path}><i className="fa fa-arrow-circle-right" /></a>
- </div>
- </Page>
- );
- });
- // TODO あとでなんとかする
- setTimeout(() => {
- $('#search-result-list > nav').affix({ offset: { top: 120 }});
- }, 1200);
- /*
- UI あとで考える
- <span className="search-result-meta">Found: {this.props.searchResultMeta.total} pages with "{this.props.searchingKeyword}"</span>
- */
- return (
- <div className="content-main">
- <div className="search-result row" id="search-result">
- <div className="col-md-4 hidden-xs hidden-sm page-list search-result-list" id="search-result-list">
- <nav data-spy="affix" data-offset-top="120">
- <ul className="page-list-ul page-list-ul-flat nav">
- {listView}
- </ul>
- </nav>
- </div>
- <div className="col-md-8 search-result-content" id="search-result-content">
- <div className="search-result-meta"><i className="fa fa-lightbulb-o" /> Found {this.props.searchResultMeta.total} pages with "{this.props.searchingKeyword}"</div>
- <SearchResultList
- pages={this.props.pages}
- searchingKeyword={this.props.searchingKeyword}
- />
- </div>
- </div>
- </div>
- );
- }
- }
- SearchResult.propTypes = {
- tree: React.PropTypes.string.isRequired,
- pages: React.PropTypes.array.isRequired,
- searchingKeyword: React.PropTypes.string.isRequired,
- searchResultMeta: React.PropTypes.object.isRequired,
- };
- SearchResult.defaultProps = {
- tree: '',
- pages: [],
- searchingKeyword: '',
- searchResultMeta: {},
- searchError: null,
- };
|