mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-17 11:41:44 +00:00
switch note by arrow buttons
This commit is contained in:
@@ -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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user