| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- 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;
- }
- render() {
- const excludePathString = this.props.tree;
- 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>
- );
- });
- /*
- 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 page-list search-result-list" id="search-result-list">
- <nav data-spy="affix" data-offset-top="120">
- <ul className="page-list-ul 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: {},
- };
|