mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
feat change name and add deletion logic
This commit is contained in:
@@ -56,7 +56,7 @@ class NoteList extends React.Component {
|
|||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
shiftKeyDown: false,
|
shiftKeyDown: false,
|
||||||
selectedNoteIds: []
|
selectedNoteKeys: []
|
||||||
}
|
}
|
||||||
|
|
||||||
this.contextNotes = []
|
this.contextNotes = []
|
||||||
@@ -135,7 +135,7 @@ class NoteList extends React.Component {
|
|||||||
}
|
}
|
||||||
let { router } = this.context
|
let { router } = this.context
|
||||||
let { location } = this.props
|
let { location } = this.props
|
||||||
let { selectedNoteIds } = this.state
|
let { selectedNoteKeys } = this.state
|
||||||
|
|
||||||
let targetIndex = this.getTargetIndex()
|
let targetIndex = this.getTargetIndex()
|
||||||
|
|
||||||
@@ -144,13 +144,13 @@ class NoteList extends React.Component {
|
|||||||
}
|
}
|
||||||
targetIndex--
|
targetIndex--
|
||||||
|
|
||||||
selectedNoteIds = []
|
selectedNoteKeys = []
|
||||||
const priorNote = Object.assign({}, this.notes[targetIndex])
|
const priorNote = Object.assign({}, this.notes[targetIndex])
|
||||||
const priorNoteKey = `${priorNote.storage}-${priorNote.key}`
|
const priorNoteKey = `${priorNote.storage}-${priorNote.key}`
|
||||||
selectedNoteIds.push(priorNoteKey)
|
selectedNoteKeys.push(priorNoteKey)
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
selectedNoteIds
|
selectedNoteKeys
|
||||||
})
|
})
|
||||||
|
|
||||||
router.push({
|
router.push({
|
||||||
@@ -167,7 +167,7 @@ class NoteList extends React.Component {
|
|||||||
}
|
}
|
||||||
let { router } = this.context
|
let { router } = this.context
|
||||||
let { location } = this.props
|
let { location } = this.props
|
||||||
let { selectedNoteIds } = this.state
|
let { selectedNoteKeys } = this.state
|
||||||
|
|
||||||
let targetIndex = this.getTargetIndex()
|
let targetIndex = this.getTargetIndex()
|
||||||
|
|
||||||
@@ -179,13 +179,13 @@ class NoteList extends React.Component {
|
|||||||
else if (targetIndex > this.notes.length - 1) targetIndex === this.notes.length - 1
|
else if (targetIndex > this.notes.length - 1) targetIndex === this.notes.length - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
selectedNoteIds = []
|
selectedNoteKeys = []
|
||||||
const nextNote = Object.assign({}, this.notes[targetIndex])
|
const nextNote = Object.assign({}, this.notes[targetIndex])
|
||||||
const nextNoteKey = `${nextNote.storage}-${nextNote.key}`
|
const nextNoteKey = `${nextNote.storage}-${nextNote.key}`
|
||||||
selectedNoteIds.push(nextNoteKey)
|
selectedNoteKeys.push(nextNoteKey)
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
selectedNoteIds
|
selectedNoteKeys
|
||||||
})
|
})
|
||||||
|
|
||||||
router.push({
|
router.push({
|
||||||
@@ -336,20 +336,20 @@ class NoteList extends React.Component {
|
|||||||
handleNoteClick (e, uniqueKey) {
|
handleNoteClick (e, uniqueKey) {
|
||||||
let { router } = this.context
|
let { router } = this.context
|
||||||
let { location } = this.props
|
let { location } = this.props
|
||||||
let { shiftKeyDown, selectedNoteIds } = this.state
|
let { shiftKeyDown, selectedNoteKeys } = this.state
|
||||||
|
|
||||||
if (shiftKeyDown && !selectedNoteIds.includes(uniqueKey)) {
|
if (shiftKeyDown && !selectedNoteKeys.includes(uniqueKey)) {
|
||||||
selectedNoteIds.push(uniqueKey)
|
selectedNoteKeys.push(uniqueKey)
|
||||||
this.setState({
|
this.setState({
|
||||||
selectedNoteIds
|
selectedNoteKeys
|
||||||
})
|
})
|
||||||
} else if (shiftKeyDown) {
|
} else if (shiftKeyDown) {
|
||||||
this.setState({
|
this.setState({
|
||||||
selectedNoteIds: [...selectedNoteIds].filter((item) => item !== uniqueKey)
|
selectedNoteKeys: [...selectedNoteKeys].filter((item) => item !== uniqueKey)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
this.setState({
|
this.setState({
|
||||||
selectedNoteIds: [uniqueKey]
|
selectedNoteKeys: [uniqueKey]
|
||||||
})
|
})
|
||||||
router.push({
|
router.push({
|
||||||
pathname: location.pathname,
|
pathname: location.pathname,
|
||||||
@@ -407,13 +407,14 @@ class NoteList extends React.Component {
|
|||||||
|
|
||||||
handleNoteContextMenu (e, uniqueKey) {
|
handleNoteContextMenu (e, uniqueKey) {
|
||||||
const { location } = this.props
|
const { location } = this.props
|
||||||
const { selectedNoteIds } = this.state
|
const { selectedNoteKeys } = this.state
|
||||||
const note = this.notes.find((note) => {
|
const note = this.notes.find((note) => {
|
||||||
const noteKey = `${note.storage}-${note.key}`
|
const noteKey = `${note.storage}-${note.key}`
|
||||||
return noteKey === uniqueKey
|
return noteKey === uniqueKey
|
||||||
})
|
})
|
||||||
|
const noteKey = `${note.storage}-${note.key}`
|
||||||
|
|
||||||
if (selectedNoteIds.length === 0) {
|
if (selectedNoteKeys.length === 0 || !selectedNoteKeys.includes(noteKey)) {
|
||||||
this.handleNoteClick(e, uniqueKey)
|
this.handleNoteClick(e, uniqueKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -459,10 +460,10 @@ class NoteList extends React.Component {
|
|||||||
|
|
||||||
deleteNote () {
|
deleteNote () {
|
||||||
const { dispatch } = this.props
|
const { dispatch } = this.props
|
||||||
const { selectedNoteIds } = this.state
|
const { selectedNoteKeys } = this.state
|
||||||
// not to change objects of this.notes
|
// not to change objects of this.notes
|
||||||
const notes = this.notes.map((note) => Object.assign({}, note))
|
const notes = this.notes.map((note) => Object.assign({}, note))
|
||||||
const selectedNotes = notes.filter((note) => selectedNoteIds.includes(`${note.storage}-${note.key}`))
|
const selectedNotes = notes.filter((note) => selectedNoteKeys.includes(`${note.storage}-${note.key}`))
|
||||||
const firstNote = selectedNotes[0]
|
const firstNote = selectedNotes[0]
|
||||||
|
|
||||||
if (firstNote.isTrashed) {
|
if (firstNote.isTrashed) {
|
||||||
@@ -475,7 +476,7 @@ class NoteList extends React.Component {
|
|||||||
})
|
})
|
||||||
if (dialogueButtonIndex === 1) return
|
if (dialogueButtonIndex === 1) return
|
||||||
Promise.all(
|
Promise.all(
|
||||||
selectedNoteIds.map((uniqueKey) => {
|
selectedNoteKeys.map((uniqueKey) => {
|
||||||
const storageKey = uniqueKey.split('-')[0]
|
const storageKey = uniqueKey.split('-')[0]
|
||||||
const noteKey = uniqueKey.split('-')[1]
|
const noteKey = uniqueKey.split('-')[1]
|
||||||
return dataApi
|
return dataApi
|
||||||
@@ -518,7 +519,7 @@ class NoteList extends React.Component {
|
|||||||
console.error('Notes could not go to trash: ' + err)
|
console.error('Notes could not go to trash: ' + err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.setState({ selectedNoteIds: [] })
|
this.setState({ selectedNoteKeys: [] })
|
||||||
}
|
}
|
||||||
|
|
||||||
importFromFile () {
|
importFromFile () {
|
||||||
@@ -588,7 +589,7 @@ class NoteList extends React.Component {
|
|||||||
|
|
||||||
render () {
|
render () {
|
||||||
let { location, notes, config, dispatch } = this.props
|
let { location, notes, config, dispatch } = this.props
|
||||||
let { selectedNoteIds } = this.state
|
let { selectedNoteKeys } = this.state
|
||||||
let sortFunc = config.sortBy === 'CREATED_AT'
|
let sortFunc = config.sortBy === 'CREATED_AT'
|
||||||
? sortByCreatedAt
|
? sortByCreatedAt
|
||||||
: config.sortBy === 'ALPHABETICAL'
|
: config.sortBy === 'ALPHABETICAL'
|
||||||
@@ -610,7 +611,7 @@ class NoteList extends React.Component {
|
|||||||
|
|
||||||
const isDefault = config.listStyle === 'DEFAULT'
|
const isDefault = config.listStyle === 'DEFAULT'
|
||||||
const uniqueKey = note.storage + '-' + note.key
|
const uniqueKey = note.storage + '-' + note.key
|
||||||
const isActive = selectedNoteIds.includes(uniqueKey)
|
const isActive = selectedNoteKeys.includes(uniqueKey)
|
||||||
const dateDisplay = moment(
|
const dateDisplay = moment(
|
||||||
config.sortBy === 'CREATED_AT'
|
config.sortBy === 'CREATED_AT'
|
||||||
? note.createdAt : note.updatedAt
|
? note.createdAt : note.updatedAt
|
||||||
|
|||||||
Reference in New Issue
Block a user