mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 02:06:29 +00:00
Add getTargetIndex() and replece them
This commit is contained in:
@@ -105,9 +105,7 @@ class NoteList extends React.Component {
|
|||||||
|
|
||||||
// Auto scroll
|
// Auto scroll
|
||||||
if (_.isString(location.query.key) && prevProps.location.query.key === location.query.key) {
|
if (_.isString(location.query.key) && prevProps.location.query.key === location.query.key) {
|
||||||
let targetIndex = _.findIndex(this.notes, (note) => {
|
const targetIndex = this.getTargetIndex()
|
||||||
return note != null && note.storage + '-' + note.key === location.query.key
|
|
||||||
})
|
|
||||||
if (targetIndex > -1) {
|
if (targetIndex > -1) {
|
||||||
let list = this.refs.list
|
let list = this.refs.list
|
||||||
let item = list.childNodes[targetIndex]
|
let item = list.childNodes[targetIndex]
|
||||||
@@ -133,9 +131,7 @@ class NoteList extends React.Component {
|
|||||||
let { router } = this.context
|
let { router } = this.context
|
||||||
let { location } = this.props
|
let { location } = this.props
|
||||||
|
|
||||||
let targetIndex = _.findIndex(this.notes, (note) => {
|
let targetIndex = this.getTargetIndex()
|
||||||
return note.storage + '-' + note.key === location.query.key
|
|
||||||
})
|
|
||||||
|
|
||||||
if (targetIndex === 0) {
|
if (targetIndex === 0) {
|
||||||
return
|
return
|
||||||
@@ -158,9 +154,7 @@ class NoteList extends React.Component {
|
|||||||
let { router } = this.context
|
let { router } = this.context
|
||||||
let { location } = this.props
|
let { location } = this.props
|
||||||
|
|
||||||
let targetIndex = _.findIndex(this.notes, (note) => {
|
let targetIndex = this.getTargetIndex()
|
||||||
return note.storage + '-' + note.key === location.query.key
|
|
||||||
})
|
|
||||||
|
|
||||||
if (targetIndex === this.notes.length - 1) {
|
if (targetIndex === this.notes.length - 1) {
|
||||||
targetIndex = 0
|
targetIndex = 0
|
||||||
@@ -188,9 +182,7 @@ class NoteList extends React.Component {
|
|||||||
const { router } = this.context
|
const { router } = this.context
|
||||||
const { location } = this.props
|
const { location } = this.props
|
||||||
|
|
||||||
let targetIndex = _.findIndex(this.notes, (note) => {
|
let targetIndex = this.getTargetIndex()
|
||||||
return note.storage + '-' + note.key === noteHash
|
|
||||||
})
|
|
||||||
|
|
||||||
if (targetIndex < 0) targetIndex = 0
|
if (targetIndex < 0) targetIndex = 0
|
||||||
|
|
||||||
@@ -333,10 +325,7 @@ class NoteList extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
alertIfSnippet () {
|
alertIfSnippet () {
|
||||||
let { location } = this.props
|
const targetIndex = this.getTargetIndex()
|
||||||
const targetIndex = _.findIndex(this.notes, (note) => {
|
|
||||||
return `${note.storage}-${note.key}` === location.query.key
|
|
||||||
})
|
|
||||||
if (this.notes[targetIndex].type === 'SNIPPET_NOTE') {
|
if (this.notes[targetIndex].type === 'SNIPPET_NOTE') {
|
||||||
dialog.showMessageBox(remote.getCurrentWindow(), {
|
dialog.showMessageBox(remote.getCurrentWindow(), {
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
@@ -354,9 +343,7 @@ class NoteList extends React.Component {
|
|||||||
|
|
||||||
handleNoteContextMenu (e, uniqueKey) {
|
handleNoteContextMenu (e, uniqueKey) {
|
||||||
const { location } = this.props
|
const { location } = this.props
|
||||||
let targetIndex = _.findIndex(this.notes, (note) => {
|
const targetIndex = this.getTargetIndex()
|
||||||
return note != null && uniqueKey === `${note.storage}-${note.key}`
|
|
||||||
})
|
|
||||||
let note = this.notes[targetIndex]
|
let note = this.notes[targetIndex]
|
||||||
const label = note.isPinned ? 'Remove pin' : 'Pin to Top'
|
const label = note.isPinned ? 'Remove pin' : 'Pin to Top'
|
||||||
|
|
||||||
@@ -382,9 +369,7 @@ class NoteList extends React.Component {
|
|||||||
const currentStorage = data.storageMap.get(storageKey)
|
const currentStorage = data.storageMap.get(storageKey)
|
||||||
const currentFolder = _.find(currentStorage.folders, {key: folderKey})
|
const currentFolder = _.find(currentStorage.folders, {key: folderKey})
|
||||||
|
|
||||||
const targetIndex = _.findIndex(this.notes, (note) => {
|
const targetIndex = this.getTargetIndex()
|
||||||
return note != null && `${note.storage}-${note.key}` === uniqueKey
|
|
||||||
})
|
|
||||||
let note = this.notes[targetIndex]
|
let note = this.notes[targetIndex]
|
||||||
note.isPinned = !note.isPinned
|
note.isPinned = !note.isPinned
|
||||||
|
|
||||||
@@ -429,9 +414,7 @@ class NoteList extends React.Component {
|
|||||||
addNotesFromFiles (filepaths) {
|
addNotesFromFiles (filepaths) {
|
||||||
const { dispatch, location } = this.props
|
const { dispatch, location } = this.props
|
||||||
|
|
||||||
const targetIndex = _.findIndex(this.notes, (note) => {
|
const targetIndex = this.getTargetIndex()
|
||||||
return note !== null && `${note.storage}-${note.key}` === location.query.key
|
|
||||||
})
|
|
||||||
|
|
||||||
const storageKey = this.notes[targetIndex].storage
|
const storageKey = this.notes[targetIndex].storage
|
||||||
const folderKey = this.notes[targetIndex].folder
|
const folderKey = this.notes[targetIndex].folder
|
||||||
@@ -462,6 +445,14 @@ class NoteList extends React.Component {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getTargetIndex () {
|
||||||
|
const { location } = this.props
|
||||||
|
const targetIndex = _.findIndex(this.notes, (note) => {
|
||||||
|
return `${note.storage}-${note.key}` === location.query.key
|
||||||
|
})
|
||||||
|
return targetIndex
|
||||||
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
let { location, notes, config, dispatch } = this.props
|
let { location, notes, config, dispatch } = this.props
|
||||||
let sortFunc = config.sortBy === 'CREATED_AT'
|
let sortFunc = config.sortBy === 'CREATED_AT'
|
||||||
|
|||||||
Reference in New Issue
Block a user