Skip to content

Commit 7a3cab8

Browse files
authored
Merge pull request #2455 from daiyam/fix-notelist
fix scrolling in note list
2 parents aec79c4 + ead6bb0 commit 7a3cab8

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

browser/main/NoteList/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import PropTypes from 'prop-types'
33
import React from 'react'
44
import CSSModules from 'browser/lib/CSSModules'
5-
import debounceRender from 'react-debounce-render'
65
import styles from './NoteList.styl'
76
import moment from 'moment'
87
import _ from 'lodash'
@@ -1130,4 +1129,4 @@ NoteList.propTypes = {
11301129
})
11311130
}
11321131

1133-
export default debounceRender(CSSModules(NoteList, styles))
1132+
export default CSSModules(NoteList, styles)

browser/main/TopBar/index.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import _ from 'lodash'
66
import ee from 'browser/main/lib/eventEmitter'
77
import NewNoteButton from 'browser/main/NewNoteButton'
88
import i18n from 'browser/lib/i18n'
9+
import debounce from 'lodash/debounce'
910

1011
class TopBar extends React.Component {
1112
constructor (props) {
@@ -25,6 +26,10 @@ class TopBar extends React.Component {
2526
}
2627

2728
this.codeInitHandler = this.handleCodeInit.bind(this)
29+
30+
this.updateKeyword = debounce(this.updateKeyword, 1000 / 60, {
31+
maxWait: 1000 / 8
32+
})
2833
}
2934

3035
componentDidMount () {
@@ -94,7 +99,6 @@ class TopBar extends React.Component {
9499
}
95100

96101
handleKeyUp (e) {
97-
const { router } = this.context
98102
// reset states
99103
this.setState({
100104
isConfirmTranslation: false
@@ -106,21 +110,21 @@ class TopBar extends React.Component {
106110
isConfirmTranslation: true
107111
})
108112
const keyword = this.refs.searchInput.value
109-
router.push(`/searched/${encodeURIComponent(keyword)}`)
110-
this.setState({
111-
search: keyword
112-
})
113+
this.updateKeyword(keyword)
113114
}
114115
}
115116

116117
handleSearchChange (e) {
117-
const { router } = this.context
118-
const keyword = this.refs.searchInput.value
119118
if (this.state.isAlphabet || this.state.isConfirmTranslation) {
120-
router.push(`/searched/${encodeURIComponent(keyword)}`)
119+
const keyword = this.refs.searchInput.value
120+
this.updateKeyword(keyword)
121121
} else {
122122
e.preventDefault()
123123
}
124+
}
125+
126+
updateKeyword (keyword) {
127+
this.context.router.push(`/searched/${encodeURIComponent(keyword)}`)
124128
this.setState({
125129
search: keyword
126130
})

0 commit comments

Comments
 (0)