Skip to content

Commit eb1a0ba

Browse files
committed
switch note by arrow buttons
1 parent 45212e7 commit eb1a0ba

1 file changed

Lines changed: 52 additions & 17 deletions

File tree

browser/main/NoteList/index.js

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,24 +61,59 @@ class NoteList extends React.Component {
6161
// ReactDOM.findDOMNode(this).focus()
6262
}
6363

64-
// 移動ができなかったらfalseを返す:
65-
selectPriorArticle () {
66-
// let { articles, activeArticle, dispatch } = this.props
67-
// let targetIndex = articles.indexOf(activeArticle) - 1
68-
// let targetArticle = articles[targetIndex]
69-
// return false
64+
selectPriorNote () {
65+
if (this.notes == null || this.notes.length === 0) {
66+
return
67+
}
68+
let { router } = this.context
69+
let { location } = this.props
70+
let splitted = location.query.key.split('-')
71+
let repoKey = splitted[0]
72+
let noteKey = splitted[1]
73+
let targetIndex = _.findIndex(this.notes, (note) => {
74+
return repoKey === note._repository.key && noteKey === note.key
75+
})
76+
77+
if (targetIndex === 0) {
78+
return
79+
}
80+
targetIndex--
81+
if (targetIndex < 0) targetIndex = 0
82+
83+
router.push({
84+
pathname: location.pathname,
85+
query: {
86+
key: `${this.notes[targetIndex]._repository.key}-${this.notes[targetIndex].key}`
87+
}
88+
})
7089
}
7190

72-
selectNextArticle () {
73-
// let { articles, activeArticle, dispatch } = this.props
74-
// let targetIndex = articles.indexOf(activeArticle) + 1
75-
// let targetArticle = articles[targetIndex]
91+
selectNextNote () {
92+
if (this.notes == null || this.notes.length === 0) {
93+
return
94+
}
95+
let { router } = this.context
96+
let { location } = this.props
97+
let splitted = location.query.key.split('-')
98+
let repoKey = splitted[0]
99+
let noteKey = splitted[1]
100+
let targetIndex = _.findIndex(this.notes, (note) => {
101+
return repoKey === note._repository.key && noteKey === note.key
102+
})
76103

77-
// if (targetArticle != null) {
78-
// dispatch(switchArticle(targetArticle.key))
79-
// return true
80-
// }
81-
// return false
104+
if (targetIndex === this.notes.length - 1) {
105+
return
106+
}
107+
targetIndex++
108+
if (targetIndex < 0) targetIndex = 0
109+
else if (targetIndex > this.notes.length - 1) targetIndex === this.notes.length - 1
110+
111+
router.push({
112+
pathname: location.pathname,
113+
query: {
114+
key: `${this.notes[targetIndex]._repository.key}-${this.notes[targetIndex].key}`
115+
}
116+
})
82117
}
83118

84119
handleNoteListKeyDown (e) {
@@ -116,12 +151,12 @@ class NoteList extends React.Component {
116151

117152
if (e.keyCode === 38) {
118153
e.preventDefault()
119-
this.selectPriorArticle()
154+
this.selectPriorNote()
120155
}
121156

122157
if (e.keyCode === 40) {
123158
e.preventDefault()
124-
this.selectNextArticle()
159+
this.selectNextNote()
125160
}
126161
}
127162

0 commit comments

Comments
 (0)