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
Next Next commit
Add pinn to top
  • Loading branch information
asmsuechan committed Oct 13, 2017
commit fe8045c51d49170938e23e14a522376098c3e280
4 changes: 4 additions & 0 deletions browser/components/NoteItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ const NoteItem = ({ isActive, note, dateDisplay, handleNoteClick, handleNoteCont
{note.isStarred
? <i styleName='item-star' className='fa fa-star' /> : ''
}
{note.isPinned
? <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
73 changes: 70 additions & 3 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 @@ -283,6 +284,21 @@ class NoteList extends React.Component {
return folderNoteKeyList.map((uniqueKey) => data.noteMap.get(uniqueKey))
}

sortByPinn (unorderedNotes) {
const { data, params } = this.props
let storageKey = params.storageKey
let folderKey = params.folderKey
let storage = data.storageMap.get(storageKey)
if (storage == null) return []

let folder = _.find(storage.folders, {key: folderKey})
const pinnedNotes = unorderedNotes.filter((el) => {
return folder.pinnedNotes && folder.pinnedNotes.includes(el.key)
})

return pinnedNotes.concat(unorderedNotes)
}

handleNoteClick (e, uniqueKey) {
let { router } = this.context
let { location } = this.props
Expand Down Expand Up @@ -413,15 +429,65 @@ class NoteList extends React.Component {
})
}

handleNoteContextMenu (e, uniqueKey) {
let menu = new Menu()
menu.append(new MenuItem({
label: 'Pin to Top',
click: (e) => this.handlePinToTop(e, uniqueKey)
}))
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 === location.query.key
})
let note = this.notes[targetIndex]

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

render () {
let { location, notes, config, dispatch } = this.props
let sortFunc = config.sortBy === 'CREATED_AT'
? sortByCreatedAt
: config.sortBy === 'ALPHABETICAL'
? sortByAlphabetical
: sortByUpdatedAt
this.notes = notes = this.getNotes()
.sort(sortFunc)
const sortedNotes = this.getNotes().sort(sortFunc)
this.notes = notes = this.sortByPinn(sortedNotes)
.filter((note) => {
// this is for the trash box
if (note.isTrashed !== true || location.pathname === '/trashed') return true
Expand Down Expand Up @@ -450,6 +516,7 @@ 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)}
/>
)
Expand Down Expand Up @@ -526,4 +593,4 @@ NoteList.propTypes = {
})
}

export default CSSModules(NoteList, styles)

3 changes: 2 additions & 1 deletion browser/main/lib/dataApi/createFolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ function createFolder (storageKey, input) {
let newFolder = {
key,
color: input.color,
name: input.name
name: input.name,
pinnedNotes: []
}

storage.folders.push(newFolder)
Expand Down
6 changes: 6 additions & 0 deletions browser/main/lib/dataApi/updateFolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ function updateFolder (storageKey, folderKey, input) {
if (targetFolder == null) throw new Error('Target folder doesn\'t exist.')
targetFolder.name = input.name
targetFolder.color = input.color
// For compativility
if (targetFolder.pinnedNotes) {
targetFolder.pinnedNotes.push(input.pinnedNote)
} else {
targetFolder.pinnedNotes = [input.pinnedNote]
}

CSON.writeFileSync(path.join(storage.path, 'boostnote.json'), _.pick(storage, ['folders', 'version']))

Expand Down
1 change: 1 addition & 0 deletions browser/main/lib/dataApi/updateNote.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ function updateNote (storageKey, noteKey, input) {
noteData.isStarred = false
noteData.isTrashed = false
noteData.tags = []
noteData.isPinned = false
}

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