Skip to content

Commit

Permalink
feat(NoteList): add ability to clone note
Browse files Browse the repository at this point in the history
  • Loading branch information
Antogin committed Jan 27, 2018
1 parent 6de5488 commit 614e9b6
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions browser/main/NoteList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ class NoteList extends React.Component {

const pinLabel = note.isPinned ? 'Remove pin' : 'Pin to Top'
const deleteLabel = 'Delete Note'
const cloneNote = 'Clone Note'

const menu = new Menu()
if (!location.pathname.match(/\/home|\/starred|\/trash/)) {
Expand All @@ -453,6 +454,10 @@ class NoteList extends React.Component {
label: deleteLabel,
click: this.deleteNote
}))
menu.append(new MenuItem({
label: cloneNote,
click: this.cloneNote.bind(this)
}))
menu.popup()
}

Expand Down Expand Up @@ -543,6 +548,45 @@ class NoteList extends React.Component {
this.setState({ selectedNoteKeys: [] })
}

cloneNote () {
const { selectedNoteKeys } = this.state
const { dispatch } = this.props
const { router } = this.context
const { storage, folder } = this.resolveTargetFolder()
const notes = this.notes.map((note) => Object.assign({}, note))
const selectedNotes = findNotesByKeys(notes, selectedNoteKeys)
const firstNote = selectedNotes[0]

AwsMobileAnalyticsConfig.recordDynamicCustomEvent('ADD_MARKDOWN')
AwsMobileAnalyticsConfig.recordDynamicCustomEvent('ADD_ALLNOTE')
dataApi
.createNote(storage.key, {
type: firstNote.type,
folder: folder.key,
title: firstNote.title + ' copy',
content: firstNote.content
})
.then((note) => {
console.log(note)
dispatch({
type: 'UPDATE_NOTE',
note: note
})
let uniqueKey = note.storage + '-'+ note.key;

this.setState({
selectedNoteKeys: [uniqueKey]
})

router.push({
pathname: location.pathname,
query: {
key: uniqueKey
}
})
})
}

importFromFile () {
const options = {
filters: [
Expand Down

0 comments on commit 614e9b6

Please sign in to comment.