Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion browser/components/NoteItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const TagElementList = (tags) => {
* @param {Function} handleDragStart
* @param {string} dateDisplay
*/
const NoteItem = ({ isActive, note, dateDisplay, handleNoteClick, handleNoteContextMenu, handleDragStart }) => (
const NoteItem = ({ isActive, note, dateDisplay, handleNoteClick, handleNoteContextMenu, handleDragStart, pathname }) => (
<div styleName={isActive
? 'item--active'
: 'item'
Expand All @@ -72,6 +72,9 @@ const NoteItem = ({ isActive, note, dateDisplay, handleNoteClick, handleNoteCont
{note.isStarred
? <i styleName='item-star' className='fa fa-star' /> : ''
}
{note.isPinned && !pathname.match(/\/home|\/starred|\/trash/)
? <i styleName='item-pin' className='fa fa-map-pin' /> : ''
}
{note.type === 'MARKDOWN_NOTE'
? <TodoProcess todoStatus={getTodoStatus(note.content)} />
: ''
Expand Down Expand Up @@ -101,6 +104,7 @@ NoteItem.propTypes = {
isTrashed: PropTypes.bool.isRequired
}),
handleNoteClick: PropTypes.func.isRequired,
handleNoteContextMenu: PropTypes.func.isRequired,
handleDragStart: PropTypes.func.isRequired,
handleDragEnd: PropTypes.func.isRequired
}
Expand Down
69 changes: 60 additions & 9 deletions browser/main/NoteList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { hashHistory } from 'react-router'
import markdown from 'browser/lib/markdown'
import { findNoteTitle } from 'browser/lib/findNoteTitle'
import stripgtags from 'striptags'
import store from 'browser/main/store'

const { remote } = require('electron')
const { Menu, MenuItem, dialog } = remote
Expand Down Expand Up @@ -251,7 +252,7 @@ class NoteList extends React.Component {
if (location.pathname.match(/\/searched/)) {
const searchInputText = document.getElementsByClassName('searchInput')[0].value
if (searchInputText === '') {
return this.contextNotes
return this.sortByPin(this.contextNotes)
}
return searchFromNotes(this.contextNotes, searchInputText)
}
Expand Down Expand Up @@ -283,6 +284,14 @@ class NoteList extends React.Component {
return folderNoteKeyList.map((uniqueKey) => data.noteMap.get(uniqueKey))
}

sortByPin (unorderedNotes) {
const pinnedNotes = unorderedNotes.filter((note) => {
return note.isPinned
})

return pinnedNotes.concat(unorderedNotes)
}

handleNoteClick (e, uniqueKey) {
let { router } = this.context
let { location } = this.props
Expand Down Expand Up @@ -344,16 +353,56 @@ 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.pinToTop(e, uniqueKey)
}))
}
menu.append(new MenuItem({
label: 'Delete Note',
click: () => ee.emit('detail:delete')
click: (e) => this.deleteNote(e, uniqueKey)
}))
menu.popup()
}

pinToTop (e, uniqueKey) {
const { data, params } = this.props
const storageKey = params.storageKey
const folderKey = params.folderKey

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

const 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
})
})
}

deleteNote (e, uniqueKey) {
this.handleNoteClick(e, uniqueKey)
ee.emit('detail:delete')
}

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

Expand Down Expand Up @@ -420,12 +469,13 @@ class NoteList extends React.Component {
: config.sortBy === 'ALPHABETICAL'
? sortByAlphabetical
: sortByUpdatedAt
this.notes = notes = this.getNotes()
.sort(sortFunc)
.filter((note) => {
// this is for the trash box
if (note.isTrashed !== true || location.pathname === '/trashed') return true
})
const sortedNotes = location.pathname.match(/\/home|\/starred|\/trash/)
? this.getNotes().sort(sortFunc)
: this.sortByPin(this.getNotes().sort(sortFunc))
this.notes = notes = sortedNotes.filter((note) => {
// this is for the trash box
if (note.isTrashed !== true || location.pathname === '/trashed') return true
})

let noteList = notes
.map(note => {
Expand All @@ -451,6 +501,7 @@ class NoteList extends React.Component {
handleNoteContextMenu={this.handleNoteContextMenu.bind(this)}
handleNoteClick={this.handleNoteClick.bind(this)}
handleDragStart={this.handleDragStart.bind(this)}
pathname={location.pathname}
/>
)
}
Expand Down
5 changes: 5 additions & 0 deletions browser/main/lib/dataApi/updateNote.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ function validateInput (input) {
validatedInput.isTrashed = !!input.isTrashed
}

if (input.isPinned !== undefined) {
validatedInput.isPinned = !!input.isPinned
}

validatedInput.type = input.type
switch (input.type) {
case 'MARKDOWN_NOTE':
Expand Down Expand Up @@ -104,6 +108,7 @@ function updateNote (storageKey, noteKey, input) {
noteData.isStarred = false
noteData.isTrashed = false
noteData.tags = []
noteData.isPinned = false
}

if (noteData.type === 'SNIPPET_NOTE') {
Expand Down