mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-15 10:46:32 +00:00
refactor: inner codes
This commit is contained in:
@@ -53,6 +53,7 @@ class NoteList extends React.Component {
|
|||||||
this.jumpNoteByHash = this.jumpNoteByHashHandler.bind(this)
|
this.jumpNoteByHash = this.jumpNoteByHashHandler.bind(this)
|
||||||
this.handleNoteListKeyUp = this.handleNoteListKeyUp.bind(this)
|
this.handleNoteListKeyUp = this.handleNoteListKeyUp.bind(this)
|
||||||
this.deleteNote = this.deleteNote.bind(this)
|
this.deleteNote = this.deleteNote.bind(this)
|
||||||
|
this.activateNote = this.activateNote.bind(this)
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
shiftKeyDown: false,
|
shiftKeyDown: false,
|
||||||
@@ -129,6 +130,22 @@ class NoteList extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
activateNote (selectedNoteKeys, noteKey) {
|
||||||
|
let { router } = this.context
|
||||||
|
let { location } = this.props
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
selectedNoteKeys
|
||||||
|
})
|
||||||
|
|
||||||
|
router.push({
|
||||||
|
pathname: location.pathname,
|
||||||
|
query: {
|
||||||
|
key: noteKey
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
selectPriorNote () {
|
selectPriorNote () {
|
||||||
if (this.notes == null || this.notes.length === 0) {
|
if (this.notes == null || this.notes.length === 0) {
|
||||||
return
|
return
|
||||||
@@ -149,16 +166,7 @@ class NoteList extends React.Component {
|
|||||||
const priorNoteKey = `${priorNote.storage}-${priorNote.key}`
|
const priorNoteKey = `${priorNote.storage}-${priorNote.key}`
|
||||||
selectedNoteKeys.push(priorNoteKey)
|
selectedNoteKeys.push(priorNoteKey)
|
||||||
|
|
||||||
this.setState({
|
this.activateNote(selectedNoteKeys, priorNoteKey)
|
||||||
selectedNoteKeys
|
|
||||||
})
|
|
||||||
|
|
||||||
router.push({
|
|
||||||
pathname: location.pathname,
|
|
||||||
query: {
|
|
||||||
key: this.notes[targetIndex].storage + '-' + this.notes[targetIndex].key
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
selectNextNote () {
|
selectNextNote () {
|
||||||
@@ -184,16 +192,8 @@ class NoteList extends React.Component {
|
|||||||
const nextNoteKey = `${nextNote.storage}-${nextNote.key}`
|
const nextNoteKey = `${nextNote.storage}-${nextNote.key}`
|
||||||
selectedNoteKeys.push(nextNoteKey)
|
selectedNoteKeys.push(nextNoteKey)
|
||||||
|
|
||||||
this.setState({
|
this.activateNote(selectedNoteKeys, nextNoteKey)
|
||||||
selectedNoteKeys
|
|
||||||
})
|
|
||||||
|
|
||||||
router.push({
|
|
||||||
pathname: location.pathname,
|
|
||||||
query: {
|
|
||||||
key: this.notes[targetIndex].storage + '-' + this.notes[targetIndex].key
|
|
||||||
}
|
|
||||||
})
|
|
||||||
ee.emit('list:moved')
|
ee.emit('list:moved')
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,12 +210,12 @@ class NoteList extends React.Component {
|
|||||||
|
|
||||||
if (targetIndex < 0) targetIndex = 0
|
if (targetIndex < 0) targetIndex = 0
|
||||||
|
|
||||||
router.push({
|
selectedNoteKeys = []
|
||||||
pathname: location.pathname,
|
const nextNote = Object.assign({}, this.notes[targetIndex])
|
||||||
query: {
|
const nextNoteKey = `${nextNote.storage}-${nextNote.key}`
|
||||||
key: this.notes[targetIndex].storage + '-' + this.notes[targetIndex].key
|
selectedNoteKeys.push(nextNoteKey)
|
||||||
}
|
|
||||||
})
|
this.activateNote(selectedNoteKeys, nextNoteKey)
|
||||||
|
|
||||||
ee.emit('list:moved')
|
ee.emit('list:moved')
|
||||||
}
|
}
|
||||||
@@ -338,26 +338,25 @@ class NoteList extends React.Component {
|
|||||||
let { location } = this.props
|
let { location } = this.props
|
||||||
let { shiftKeyDown, selectedNoteKeys } = this.state
|
let { shiftKeyDown, selectedNoteKeys } = this.state
|
||||||
|
|
||||||
if (shiftKeyDown && !selectedNoteKeys.includes(uniqueKey)) {
|
if (shiftKeyDown && selectedNoteKeys.includes(uniqueKey)) {
|
||||||
selectedNoteKeys.push(uniqueKey)
|
|
||||||
this.setState({
|
|
||||||
selectedNoteKeys
|
|
||||||
})
|
|
||||||
} else if (shiftKeyDown) {
|
|
||||||
this.setState({
|
this.setState({
|
||||||
selectedNoteKeys: [...selectedNoteKeys].filter((item) => item !== uniqueKey)
|
selectedNoteKeys: [...selectedNoteKeys].filter((item) => item !== uniqueKey)
|
||||||
})
|
})
|
||||||
} else {
|
return
|
||||||
this.setState({
|
|
||||||
selectedNoteKeys: [uniqueKey]
|
|
||||||
})
|
|
||||||
router.push({
|
|
||||||
pathname: location.pathname,
|
|
||||||
query: {
|
|
||||||
key: uniqueKey
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
if (!shiftKeyDown) {
|
||||||
|
selectedNoteKeys = []
|
||||||
|
}
|
||||||
|
selectedNoteKeys.push(uniqueKey)
|
||||||
|
this.setState({
|
||||||
|
selectedNoteKeys
|
||||||
|
})
|
||||||
|
router.push({
|
||||||
|
pathname: location.pathname,
|
||||||
|
query: {
|
||||||
|
key: uniqueKey
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSortByChange (e) {
|
handleSortByChange (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user