mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
fix: fix crash on /searched
Add routing for search word: - `/searched/:searchword` Restore the state from the `:searchword` params.
This commit is contained in:
@@ -326,8 +326,10 @@ class NoteList extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (location.pathname.match(/\/searched/)) {
|
if (location.pathname.match(/\/searched/)) {
|
||||||
const searchInputText = document.getElementsByClassName('searchInput')[0].value
|
const searchInputText = params.searchword
|
||||||
if (searchInputText === '') {
|
const allNotes = data.noteMap.map((note) => note)
|
||||||
|
this.contextNotes = allNotes
|
||||||
|
if (searchInputText === undefined || searchInputText === '') {
|
||||||
return this.sortByPin(this.contextNotes)
|
return this.sortByPin(this.contextNotes)
|
||||||
}
|
}
|
||||||
return searchFromNotes(this.contextNotes, searchInputText)
|
return searchFromNotes(this.contextNotes, searchInputText)
|
||||||
|
|||||||
@@ -28,6 +28,14 @@ class TopBar extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
|
const { params } = this.props
|
||||||
|
const searchWord = params.searchword
|
||||||
|
if (searchWord !== undefined) {
|
||||||
|
this.setState({
|
||||||
|
search: searchWord,
|
||||||
|
isSearching: true
|
||||||
|
})
|
||||||
|
}
|
||||||
ee.on('top:focus-search', this.focusSearchHandler)
|
ee.on('top:focus-search', this.focusSearchHandler)
|
||||||
ee.on('code:init', this.codeInitHandler)
|
ee.on('code:init', this.codeInitHandler)
|
||||||
}
|
}
|
||||||
@@ -97,9 +105,10 @@ class TopBar extends React.Component {
|
|||||||
this.setState({
|
this.setState({
|
||||||
isConfirmTranslation: true
|
isConfirmTranslation: true
|
||||||
})
|
})
|
||||||
router.push('/searched')
|
const keyword = this.refs.searchInput.value
|
||||||
|
router.push(`/searched/${encodeURIComponent(keyword)}`)
|
||||||
this.setState({
|
this.setState({
|
||||||
search: this.refs.searchInput.value
|
search: keyword
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,7 +117,7 @@ class TopBar extends React.Component {
|
|||||||
const { router } = this.context
|
const { router } = this.context
|
||||||
const keyword = this.refs.searchInput.value
|
const keyword = this.refs.searchInput.value
|
||||||
if (this.state.isAlphabet || this.state.isConfirmTranslation) {
|
if (this.state.isAlphabet || this.state.isConfirmTranslation) {
|
||||||
router.push('/searched')
|
router.push(`/searched/${encodeURIComponent(keyword)}`)
|
||||||
} else {
|
} else {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,9 @@ ReactDOM.render((
|
|||||||
<IndexRedirect to='/home' />
|
<IndexRedirect to='/home' />
|
||||||
<Route path='home' />
|
<Route path='home' />
|
||||||
<Route path='starred' />
|
<Route path='starred' />
|
||||||
<Route path='searched' />
|
<Route path='searched'>
|
||||||
|
<Route path=':searchword' />
|
||||||
|
</Route>
|
||||||
<Route path='trashed' />
|
<Route path='trashed' />
|
||||||
<Route path='alltags' />
|
<Route path='alltags' />
|
||||||
<Route path='tags'>
|
<Route path='tags'>
|
||||||
|
|||||||
Reference in New Issue
Block a user