Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Resolve conflicts
  • Loading branch information
asmsuechan committed Oct 13, 2017
commit 725c6a7ba9e55a0b4757ce56c01e318b7d0f7022
4 changes: 1 addition & 3 deletions browser/components/NoteItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ const TagElementList = (tags) => {
* @param {Function} handleNoteContextMenu
* @param {Function} handleDragStart
* @param {string} dateDisplay
* @param {Function} handleNoteContextMenu
* @param {string} pathname
*/
const NoteItem = ({ isActive, note, dateDisplay, handleNoteClick, handleDragStart, handleNoteContextMenu, pathname }) => (
const NoteItem = ({ isActive, note, dateDisplay, handleNoteClick, handleNoteContextMenu, handleDragStart, pathname }) => (
<div styleName={isActive
? 'item--active'
: 'item'
Expand Down
117 changes: 55 additions & 62 deletions browser/main/NoteList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,68 @@ class NoteList extends React.Component {
handleNoteContextMenu (e, uniqueKey) {
this.handleNoteClick(e, uniqueKey)

const { location } = this.props
let targetIndex = _.findIndex(this.notes, (note) => {
return note != null && uniqueKey === `${note.storage}-${note.key}`
})
let note = this.notes[targetIndex]
const label = note.isPinned ? 'Remove pin' : 'Pin to Top'

let menu = new Menu()
if (!location.pathname.match(/\/home|\/starred|\/trash/)) {
menu.append(new MenuItem({
label: label,
click: (e) => this.handlePinToTop(e, uniqueKey)
}))
}
menu.append(new MenuItem({
label: 'Delete Note',
click: () => ee.emit('detail:delete')
}))
menu.popup()
}

handlePinToTop (e, uniqueKey) {
const { data, location } = this.props
let splitted = location.pathname.split('/')
const storageKey = splitted[2]
const folderKey = splitted[4]

const currentStorage = data.storageMap.get(storageKey)
const currentFolder = _.find(currentStorage.folders, {key: folderKey})

dataApi
.updateFolder(storageKey, folderKey, {
color: currentFolder.color,
name: currentFolder.name,
pinnedNote: uniqueKey.split('-').pop()
})
.then((data) => {
store.dispatch({
type: 'UPDATE_FOLDER',
storage: data.storage
})
this.setState({
status: 'IDLE'
})
})

let targetIndex = _.findIndex(this.notes, (note) => {
return note != null && note.storage + '-' + note.key === uniqueKey
})
let note = this.notes[targetIndex]
note.isPinned = !note.isPinned

dataApi
.updateNote(note.storage, note.key, note)
.then((note) => {
store.dispatch({
type: 'UPDATE_NOTE',
note: note
})
})
}

importFromFile () {
const { dispatch, location } = this.props

Expand Down Expand Up @@ -433,66 +487,6 @@ class NoteList extends React.Component {
})
}

handleNoteContextMenu (e, uniqueKey) {
const { location } = this.props
let targetIndex = _.findIndex(this.notes, (note) => {
return note != null && uniqueKey === `${note.storage}-${note.key}`
})
let note = this.notes[targetIndex]
const label = note.isPinned ? 'Remove pin' : 'Pin to Top'

let menu = new Menu()
menu.append(new MenuItem({
label: label,
click: (e) => this.handlePinToTop(e, uniqueKey)
}))

if (!location.pathname.match(/\/home|\/starred|\/trash/)) {
menu.popup()
}
}

handlePinToTop (e, uniqueKey) {
const { data, location } = this.props
let splitted = location.pathname.split('/')
const storageKey = splitted[2]
const folderKey = splitted[4]

const currentStorage = data.storageMap.get(storageKey)
const currentFolder = _.find(currentStorage.folders, {key: folderKey})

dataApi
.updateFolder(storageKey, folderKey, {
color: currentFolder.color,
name: currentFolder.name,
pinnedNote: uniqueKey.split('-').pop()
})
.then((data) => {
store.dispatch({
type: 'UPDATE_FOLDER',
storage: data.storage
})
this.setState({
status: 'IDLE'
})
})

let targetIndex = _.findIndex(this.notes, (note) => {
return note != null && note.storage + '-' + note.key === uniqueKey
})
let note = this.notes[targetIndex]
note.isPinned = !note.isPinned

dataApi
.updateNote(note.storage, note.key, note)
.then((note) => {
store.dispatch({
type: 'UPDATE_NOTE',
note: note
})
})
}

render () {
let { location, notes, config, dispatch } = this.props
let sortFunc = config.sortBy === 'CREATED_AT'
Expand Down Expand Up @@ -530,7 +524,6 @@ class NoteList extends React.Component {
key={key}
handleNoteContextMenu={this.handleNoteContextMenu.bind(this)}
handleNoteClick={this.handleNoteClick.bind(this)}
handleNoteContextMenu={this.handleNoteContextMenu.bind(this)}
handleDragStart={this.handleDragStart.bind(this)}
pathname={location.pathname}
/>
Expand Down Expand Up @@ -608,4 +601,4 @@ NoteList.propTypes = {
})
}


export default CSSModules(NoteList, styles)