1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-16 19:21:52 +00:00

switch note by arrow buttons

This commit is contained in:
Dick Choi
2016-06-01 11:50:58 +09:00
parent 45212e7e14
commit eb1a0ba49f

View File

@@ -61,24 +61,59 @@ class NoteList extends React.Component {
// ReactDOM.findDOMNode(this).focus() // ReactDOM.findDOMNode(this).focus()
} }
// 移動ができなかったらfalseを返す: selectPriorNote () {
selectPriorArticle () { if (this.notes == null || this.notes.length === 0) {
// let { articles, activeArticle, dispatch } = this.props return
// let targetIndex = articles.indexOf(activeArticle) - 1 }
// let targetArticle = articles[targetIndex] let { router } = this.context
// return false let { location } = this.props
let splitted = location.query.key.split('-')
let repoKey = splitted[0]
let noteKey = splitted[1]
let targetIndex = _.findIndex(this.notes, (note) => {
return repoKey === note._repository.key && noteKey === note.key
})
if (targetIndex === 0) {
return
}
targetIndex--
if (targetIndex < 0) targetIndex = 0
router.push({
pathname: location.pathname,
query: {
key: `${this.notes[targetIndex]._repository.key}-${this.notes[targetIndex].key}`
}
})
} }
selectNextArticle () { selectNextNote () {
// let { articles, activeArticle, dispatch } = this.props if (this.notes == null || this.notes.length === 0) {
// let targetIndex = articles.indexOf(activeArticle) + 1 return
// let targetArticle = articles[targetIndex] }
let { router } = this.context
let { location } = this.props
let splitted = location.query.key.split('-')
let repoKey = splitted[0]
let noteKey = splitted[1]
let targetIndex = _.findIndex(this.notes, (note) => {
return repoKey === note._repository.key && noteKey === note.key
})
// if (targetArticle != null) { if (targetIndex === this.notes.length - 1) {
// dispatch(switchArticle(targetArticle.key)) return
// return true }
// } targetIndex++
// return false if (targetIndex < 0) targetIndex = 0
else if (targetIndex > this.notes.length - 1) targetIndex === this.notes.length - 1
router.push({
pathname: location.pathname,
query: {
key: `${this.notes[targetIndex]._repository.key}-${this.notes[targetIndex].key}`
}
})
} }
handleNoteListKeyDown (e) { handleNoteListKeyDown (e) {
@@ -116,12 +151,12 @@ class NoteList extends React.Component {
if (e.keyCode === 38) { if (e.keyCode === 38) {
e.preventDefault() e.preventDefault()
this.selectPriorArticle() this.selectPriorNote()
} }
if (e.keyCode === 40) { if (e.keyCode === 40) {
e.preventDefault() e.preventDefault()
this.selectNextArticle() this.selectNextNote()
} }
} }