1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

Add unpin

This commit is contained in:
asmsuechan
2017-10-11 13:31:40 +09:00
parent fe8045c51d
commit 8fd4deb3eb
2 changed files with 22 additions and 4 deletions

View File

@@ -292,8 +292,9 @@ class NoteList extends React.Component {
if (storage == null) return [] if (storage == null) return []
let folder = _.find(storage.folders, {key: folderKey}) let folder = _.find(storage.folders, {key: folderKey})
if (folder === undefined) return unorderedNotes
const pinnedNotes = unorderedNotes.filter((el) => { const pinnedNotes = unorderedNotes.filter((el) => {
return folder.pinnedNotes && folder.pinnedNotes.includes(el.key) return el.isPinned
}) })
return pinnedNotes.concat(unorderedNotes) return pinnedNotes.concat(unorderedNotes)
@@ -430,9 +431,16 @@ class NoteList extends React.Component {
} }
handleNoteContextMenu (e, uniqueKey) { handleNoteContextMenu (e, uniqueKey) {
let targetIndex = _.findIndex(this.notes, (note) => {
return note != null && uniqueKey === `${note.storage}-${note.key}`
})
let note = this.notes[targetIndex]
console.log(note)
const label = note.isPinned ? 'Remove pin' : 'Pin to Top'
let menu = new Menu() let menu = new Menu()
menu.append(new MenuItem({ menu.append(new MenuItem({
label: 'Pin to Top', label: label,
click: (e) => this.handlePinToTop(e, uniqueKey) click: (e) => this.handlePinToTop(e, uniqueKey)
})) }))
menu.popup() menu.popup()
@@ -464,14 +472,20 @@ class NoteList extends React.Component {
}) })
let targetIndex = _.findIndex(this.notes, (note) => { let targetIndex = _.findIndex(this.notes, (note) => {
return note != null && note.storage + '-' + note.key === location.query.key return note != null && note.storage + '-' + note.key === uniqueKey
}) })
let note = this.notes[targetIndex] let note = this.notes[targetIndex]
if (note.isPinned) {
note.isPinned = false
console.log('unpinned')
} else {
note.isPinned = true
console.log('pinned')
}
dataApi dataApi
.updateNote(note.storage, note.key, note) .updateNote(note.storage, note.key, note)
.then((note) => { .then((note) => {
note.isPinned = true
store.dispatch({ store.dispatch({
type: 'UPDATE_NOTE', type: 'UPDATE_NOTE',
note: note note: note

View File

@@ -26,6 +26,10 @@ function validateInput (input) {
validatedInput.isTrashed = !!input.isTrashed validatedInput.isTrashed = !!input.isTrashed
} }
if (input.isPinned !== undefined) {
validatedInput.isPinned = !!input.isPinned
}
validatedInput.type = input.type validatedInput.type = input.type
switch (input.type) { switch (input.type) {
case 'MARKDOWN_NOTE': case 'MARKDOWN_NOTE':