Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | // This is the root component for #page-list-search import React from 'react' import queryString from 'query-string' import SearchResult from './SearchPage/SearchResult' import Crowi from 'client/util/Crowi' interface Props { crowi: Crowi } interface State { tree: string searchingKeyword: string searchedKeyword: string searchedPages: [] searchResultMeta: {} searchError: Error | null } export default class PageListSearch extends React.Component<Props, State> { constructor(props: Props) { super(props) const { search = '' } = this.props.crowi.location const { q = '' } = queryString.parse(search) this.state = { tree: $('#search-listpage-input').data('path'), searchingKeyword: String(q), searchedKeyword: '', searchedPages: [], searchResultMeta: {}, searchError: null, } this.changeURL = this.changeURL.bind(this) this.search = this.search.bind(this) this.handleChange = this.handleChange.bind(this) } componentDidMount() { const $pageListSearchForm = $('#search-listpage-input') // search after page initialized if (this.state.searchingKeyword !== '') { const keyword = this.state.searchingKeyword $pageListSearchForm.val(keyword) this.search({ keyword }) } // This is temporary data bind ... (out of component) $('#search-listpage-form').on('submit', () => { const keyword = String($pageListSearchForm.val()) if (keyword != this.state.searchingKeyword) { this.search({ keyword }) } return false }) $('#search-listpage-clear').on('click', () => { $pageListSearchForm.val('') this.search({ keyword: '' }) return false }) } componentWillUnmount() {} handleChange(event: React.ChangeEvent<HTMLInputElement>) { // this is not fired now because of force-data-bound by jQuery const keyword = event.target.value this.setState({ searchedKeyword: keyword }) // console.log('Changed'); } stopSearching() { $('#content-main').show() $('#search-listpage-clear').hide() $('.main-container').removeClass('aside-hidden') } startSearching() { $('#content-main').hide() $('#search-listpage-clear').show() $('.main-container').addClass('aside-hidden') } changeURL(keyword: string, refreshHash = false) { const tree = this.state.tree let { hash = '' } = this.props.crowi.location // TODO 整理する if (refreshHash || this.state.searchedKeyword !== '') { hash = '' } if (window.history && window.history.pushState) { window.history.pushState('', `Search - ${keyword}`, `${tree}?q=${keyword}${hash}`) } } search(data: { keyword: string }) { const keyword = data.keyword || '' const tree = this.state.tree this.changeURL(keyword) if (keyword === '') { this.stopSearching() this.setState({ searchingKeyword: '', searchedPages: [], searchResultMeta: {}, searchError: null, }) return true } this.startSearching() this.setState({ searchingKeyword: keyword, }) this.props.crowi .apiGet('/search', { q: keyword, tree: tree }) .then(res => { this.setState({ searchedKeyword: keyword, searchedPages: res.data, searchResultMeta: res.meta, }) }) .catch(err => { this.setState({ searchError: err, }) }) } render() { return ( <div> <input type="hidden" name="q" value={this.state.searchingKeyword} onChange={this.handleChange} className="form-control" /> <div className="content-main"> <SearchResult tree={this.state.tree} pages={this.state.searchedPages} searchingKeyword={this.state.searchingKeyword} searchResultMeta={this.state.searchResultMeta} searchError={this.state.searchError} /> </div> </div> ) } } |