Skip to content

Commit 5836b65

Browse files
authored
Merge pull request #1744 from azu/search-routing
fix reload crash on /searched
2 parents 46f750e + 3b0f664 commit 5836b65

3 files changed

Lines changed: 19 additions & 6 deletions

File tree

browser/main/NoteList/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,10 @@ class NoteList extends React.Component {
326326
}
327327

328328
if (location.pathname.match(/\/searched/)) {
329-
const searchInputText = document.getElementsByClassName('searchInput')[0].value
330-
if (searchInputText === '') {
329+
const searchInputText = params.searchword
330+
const allNotes = data.noteMap.map((note) => note)
331+
this.contextNotes = allNotes
332+
if (searchInputText === undefined || searchInputText === '') {
331333
return this.sortByPin(this.contextNotes)
332334
}
333335
return searchFromNotes(this.contextNotes, searchInputText)

browser/main/TopBar/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ class TopBar extends React.Component {
2828
}
2929

3030
componentDidMount () {
31+
const { params } = this.props
32+
const searchWord = params.searchword
33+
if (searchWord !== undefined) {
34+
this.setState({
35+
search: searchWord,
36+
isSearching: true
37+
})
38+
}
3139
ee.on('top:focus-search', this.focusSearchHandler)
3240
ee.on('code:init', this.codeInitHandler)
3341
}
@@ -97,9 +105,10 @@ class TopBar extends React.Component {
97105
this.setState({
98106
isConfirmTranslation: true
99107
})
100-
router.push('/searched')
108+
const keyword = this.refs.searchInput.value
109+
router.push(`/searched/${encodeURIComponent(keyword)}`)
101110
this.setState({
102-
search: this.refs.searchInput.value
111+
search: keyword
103112
})
104113
}
105114
}
@@ -108,7 +117,7 @@ class TopBar extends React.Component {
108117
const { router } = this.context
109118
const keyword = this.refs.searchInput.value
110119
if (this.state.isAlphabet || this.state.isConfirmTranslation) {
111-
router.push('/searched')
120+
router.push(`/searched/${encodeURIComponent(keyword)}`)
112121
} else {
113122
e.preventDefault()
114123
}

browser/main/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ ReactDOM.render((
6464
<IndexRedirect to='/home' />
6565
<Route path='home' />
6666
<Route path='starred' />
67-
<Route path='searched' />
67+
<Route path='searched'>
68+
<Route path=':searchword' />
69+
</Route>
6870
<Route path='trashed' />
6971
<Route path='alltags' />
7072
<Route path='tags'>

0 commit comments

Comments
 (0)