From fe8045c51d49170938e23e14a522376098c3e280 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Fri, 13 Oct 2017 13:10:39 +0900 Subject: [PATCH 01/17] Add pinn to top --- browser/components/NoteItem.js | 4 ++ browser/main/NoteList/index.js | 73 +++++++++++++++++++++++- browser/main/lib/dataApi/createFolder.js | 3 +- browser/main/lib/dataApi/updateFolder.js | 6 ++ browser/main/lib/dataApi/updateNote.js | 1 + 5 files changed, 83 insertions(+), 4 deletions(-) diff --git a/browser/components/NoteItem.js b/browser/components/NoteItem.js index 9f49fb288..ce209471a 100644 --- a/browser/components/NoteItem.js +++ b/browser/components/NoteItem.js @@ -72,6 +72,9 @@ const NoteItem = ({ isActive, note, dateDisplay, handleNoteClick, handleNoteCont {note.isStarred ? : '' } + {note.isPinned + ? : '' + } {note.type === 'MARKDOWN_NOTE' ? : '' @@ -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 } diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 6f3860eb1..8fad912c3 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -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 @@ -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 @@ -413,6 +429,56 @@ 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' @@ -420,8 +486,8 @@ class NoteList extends React.Component { : 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 @@ -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)} /> ) @@ -526,4 +593,4 @@ NoteList.propTypes = { }) } -export default CSSModules(NoteList, styles) + diff --git a/browser/main/lib/dataApi/createFolder.js b/browser/main/lib/dataApi/createFolder.js index 9357e17cb..69c27d38b 100644 --- a/browser/main/lib/dataApi/createFolder.js +++ b/browser/main/lib/dataApi/createFolder.js @@ -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) diff --git a/browser/main/lib/dataApi/updateFolder.js b/browser/main/lib/dataApi/updateFolder.js index e128a2d32..414e32b63 100644 --- a/browser/main/lib/dataApi/updateFolder.js +++ b/browser/main/lib/dataApi/updateFolder.js @@ -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'])) diff --git a/browser/main/lib/dataApi/updateNote.js b/browser/main/lib/dataApi/updateNote.js index 4bf5ca291..e6bc7b559 100644 --- a/browser/main/lib/dataApi/updateNote.js +++ b/browser/main/lib/dataApi/updateNote.js @@ -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') { From 8fd4deb3ebd2423c397a851d315b903b7ed0cc93 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Wed, 11 Oct 2017 13:31:40 +0900 Subject: [PATCH 02/17] Add unpin --- browser/main/NoteList/index.js | 22 ++++++++++++++++++---- browser/main/lib/dataApi/updateNote.js | 4 ++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 8fad912c3..f953694c7 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -292,8 +292,9 @@ class NoteList extends React.Component { if (storage == null) return [] let folder = _.find(storage.folders, {key: folderKey}) + if (folder === undefined) return unorderedNotes const pinnedNotes = unorderedNotes.filter((el) => { - return folder.pinnedNotes && folder.pinnedNotes.includes(el.key) + return el.isPinned }) return pinnedNotes.concat(unorderedNotes) @@ -430,9 +431,16 @@ class NoteList extends React.Component { } 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() menu.append(new MenuItem({ - label: 'Pin to Top', + label: label, click: (e) => this.handlePinToTop(e, uniqueKey) })) menu.popup() @@ -464,14 +472,20 @@ class NoteList extends React.Component { }) 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] + if (note.isPinned) { + note.isPinned = false + console.log('unpinned') + } else { + note.isPinned = true + console.log('pinned') + } dataApi .updateNote(note.storage, note.key, note) .then((note) => { - note.isPinned = true store.dispatch({ type: 'UPDATE_NOTE', note: note diff --git a/browser/main/lib/dataApi/updateNote.js b/browser/main/lib/dataApi/updateNote.js index e6bc7b559..cf3fc047d 100644 --- a/browser/main/lib/dataApi/updateNote.js +++ b/browser/main/lib/dataApi/updateNote.js @@ -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': From 0ccb465288863cbad4e6ea59a16cfeefea81a97e Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Wed, 11 Oct 2017 13:35:24 +0900 Subject: [PATCH 03/17] Remove pinnedNotes from Folder --- browser/main/NoteList/index.js | 4 ++-- browser/main/lib/dataApi/createFolder.js | 3 +-- browser/main/lib/dataApi/updateFolder.js | 5 ----- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index f953694c7..80932652c 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -293,8 +293,8 @@ class NoteList extends React.Component { let folder = _.find(storage.folders, {key: folderKey}) if (folder === undefined) return unorderedNotes - const pinnedNotes = unorderedNotes.filter((el) => { - return el.isPinned + const pinnedNotes = unorderedNotes.filter((note) => { + return note.isPinned }) return pinnedNotes.concat(unorderedNotes) diff --git a/browser/main/lib/dataApi/createFolder.js b/browser/main/lib/dataApi/createFolder.js index 69c27d38b..9357e17cb 100644 --- a/browser/main/lib/dataApi/createFolder.js +++ b/browser/main/lib/dataApi/createFolder.js @@ -44,8 +44,7 @@ function createFolder (storageKey, input) { let newFolder = { key, color: input.color, - name: input.name, - pinnedNotes: [] + name: input.name } storage.folders.push(newFolder) diff --git a/browser/main/lib/dataApi/updateFolder.js b/browser/main/lib/dataApi/updateFolder.js index 414e32b63..baddcb17a 100644 --- a/browser/main/lib/dataApi/updateFolder.js +++ b/browser/main/lib/dataApi/updateFolder.js @@ -45,11 +45,6 @@ function updateFolder (storageKey, folderKey, input) { 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'])) From 5433abddaf48cf97c7c5f0785ea844b38257deb4 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Wed, 11 Oct 2017 13:39:12 +0900 Subject: [PATCH 04/17] Remove console.log --- browser/main/NoteList/index.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 80932652c..98405a621 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -435,7 +435,6 @@ class NoteList extends React.Component { 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() @@ -475,13 +474,7 @@ class NoteList extends React.Component { return note != null && note.storage + '-' + note.key === uniqueKey }) let note = this.notes[targetIndex] - if (note.isPinned) { - note.isPinned = false - console.log('unpinned') - } else { - note.isPinned = true - console.log('pinned') - } + note.isPinned = note.isPinned ? false : true dataApi .updateNote(note.storage, note.key, note) From 644039519767c08d35d790736f138be0609975a4 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Fri, 13 Oct 2017 13:12:00 +0900 Subject: [PATCH 05/17] Change to use strict equation --- browser/main/NoteList/index.js | 2 +- browser/main/lib/dataApi/updateFolder.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 98405a621..6c385ec6c 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -289,7 +289,7 @@ class NoteList extends React.Component { let storageKey = params.storageKey let folderKey = params.folderKey let storage = data.storageMap.get(storageKey) - if (storage == null) return [] + if (storage === undefined) return [] let folder = _.find(storage.folders, {key: folderKey}) if (folder === undefined) return unorderedNotes diff --git a/browser/main/lib/dataApi/updateFolder.js b/browser/main/lib/dataApi/updateFolder.js index baddcb17a..e128a2d32 100644 --- a/browser/main/lib/dataApi/updateFolder.js +++ b/browser/main/lib/dataApi/updateFolder.js @@ -44,7 +44,6 @@ 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 CSON.writeFileSync(path.join(storage.path, 'boostnote.json'), _.pick(storage, ['folders', 'version'])) From 0e312ba929daa0d44f1c292488819406b63fbfb8 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Wed, 11 Oct 2017 14:56:41 +0900 Subject: [PATCH 06/17] Change name Pinn to Pin --- browser/main/NoteList/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 6c385ec6c..9c1b30c6a 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -284,7 +284,7 @@ class NoteList extends React.Component { return folderNoteKeyList.map((uniqueKey) => data.noteMap.get(uniqueKey)) } - sortByPinn (unorderedNotes) { + sortByPin (unorderedNotes) { const { data, params } = this.props let storageKey = params.storageKey let folderKey = params.folderKey @@ -494,7 +494,7 @@ class NoteList extends React.Component { ? sortByAlphabetical : sortByUpdatedAt const sortedNotes = this.getNotes().sort(sortFunc) - this.notes = notes = this.sortByPinn(sortedNotes) + this.notes = notes = this.sortByPin(sortedNotes) .filter((note) => { // this is for the trash box if (note.isTrashed !== true || location.pathname === '/trashed') return true From f3370242bfa41eb69cdb2afd901964c857ed035d Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Fri, 13 Oct 2017 13:12:41 +0900 Subject: [PATCH 07/17] Add conditions to hide pin from /home, /starred or /trash --- browser/components/NoteItem.js | 4 ++-- browser/main/NoteList/index.js | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/browser/components/NoteItem.js b/browser/components/NoteItem.js index ce209471a..b6e066e06 100644 --- a/browser/components/NoteItem.js +++ b/browser/components/NoteItem.js @@ -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, handleDragStart, handleNoteContextMenu, pathname }) => (
: '' } - {note.isPinned + {note.isPinned && !pathname.match(/\/home|\/starred|\/trash/) ? : '' } {note.type === 'MARKDOWN_NOTE' diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 9c1b30c6a..dfd9a74e4 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -285,10 +285,13 @@ class NoteList extends React.Component { } sortByPin (unorderedNotes) { - const { data, params } = this.props + const { data, params, location } = this.props let storageKey = params.storageKey let folderKey = params.folderKey let storage = data.storageMap.get(storageKey) + if (location.pathname.match(/\/home|\/starred|\/trash/)){ + return unorderedNotes + } if (storage === undefined) return [] let folder = _.find(storage.folders, {key: folderKey}) @@ -431,18 +434,23 @@ 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) })) - menu.popup() + + if (!location.pathname.match(/\/home|\/starred|\/trash/)){ + menu.popup() + } } handlePinToTop (e, uniqueKey) { @@ -525,6 +533,7 @@ class NoteList extends React.Component { handleNoteClick={this.handleNoteClick.bind(this)} handleNoteContextMenu={this.handleNoteContextMenu.bind(this)} handleDragStart={this.handleDragStart.bind(this)} + pathname={location.pathname} /> ) } From d915d194256f2295553bb6c4694c06225071b7ff Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Thu, 12 Oct 2017 09:07:50 +0900 Subject: [PATCH 08/17] Add comment for NoteItem --- browser/components/NoteItem.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/browser/components/NoteItem.js b/browser/components/NoteItem.js index b6e066e06..31dd1877e 100644 --- a/browser/components/NoteItem.js +++ b/browser/components/NoteItem.js @@ -44,6 +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 }) => (
Date: Thu, 12 Oct 2017 10:01:38 +0900 Subject: [PATCH 09/17] Fix some pointed by eslint --- browser/main/NoteList/index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index dfd9a74e4..b3718bec2 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -289,7 +289,7 @@ class NoteList extends React.Component { let storageKey = params.storageKey let folderKey = params.folderKey let storage = data.storageMap.get(storageKey) - if (location.pathname.match(/\/home|\/starred|\/trash/)){ + if (location.pathname.match(/\/home|\/starred|\/trash/)) { return unorderedNotes } if (storage === undefined) return [] @@ -441,14 +441,13 @@ class NoteList extends React.Component { 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/)){ + if (!location.pathname.match(/\/home|\/starred|\/trash/)) { menu.popup() } } @@ -482,7 +481,7 @@ class NoteList extends React.Component { return note != null && note.storage + '-' + note.key === uniqueKey }) let note = this.notes[targetIndex] - note.isPinned = note.isPinned ? false : true + note.isPinned = !note.isPinned dataApi .updateNote(note.storage, note.key, note) From 725c6a7ba9e55a0b4757ce56c01e318b7d0f7022 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Fri, 13 Oct 2017 13:34:43 +0900 Subject: [PATCH 10/17] Resolve conflicts --- browser/components/NoteItem.js | 4 +- browser/main/NoteList/index.js | 117 ++++++++++++++++----------------- 2 files changed, 56 insertions(+), 65 deletions(-) diff --git a/browser/components/NoteItem.js b/browser/components/NoteItem.js index 31dd1877e..35c6d976d 100644 --- a/browser/components/NoteItem.js +++ b/browser/components/NoteItem.js @@ -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 }) => (
{ + 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') @@ -374,6 +387,47 @@ class NoteList extends React.Component { 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 @@ -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' @@ -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} /> @@ -608,4 +601,4 @@ NoteList.propTypes = { }) } - +export default CSSModules(NoteList, styles) From 2415fbf676b1a5db00bbbfde6ad9c048ffee0ca4 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Fri, 13 Oct 2017 13:41:08 +0900 Subject: [PATCH 11/17] Change to use const instead of let --- browser/main/NoteList/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index b9928b9d5..cb67bc0d5 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -286,15 +286,15 @@ class NoteList extends React.Component { sortByPin (unorderedNotes) { const { data, params, location } = this.props - let storageKey = params.storageKey - let folderKey = params.folderKey - let storage = data.storageMap.get(storageKey) + const storageKey = params.storageKey + const folderKey = params.folderKey + const storage = data.storageMap.get(storageKey) if (location.pathname.match(/\/home|\/starred|\/trash/)) { return unorderedNotes } if (storage === undefined) return [] - let folder = _.find(storage.folders, {key: folderKey}) + const folder = _.find(storage.folders, {key: folderKey}) if (folder === undefined) return unorderedNotes const pinnedNotes = unorderedNotes.filter((note) => { return note.isPinned From 3027cc81b39e07417e3f66ad79a1b297c5b0d86e Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Fri, 13 Oct 2017 13:50:00 +0900 Subject: [PATCH 12/17] Add handleNoteDelete --- browser/main/NoteList/index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index cb67bc0d5..f533b6bac 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -364,8 +364,6 @@ 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}` @@ -382,7 +380,7 @@ class NoteList extends React.Component { } menu.append(new MenuItem({ label: 'Delete Note', - click: () => ee.emit('detail:delete') + click: (e) => this.handleDeleteNote(e, uniqueKey) })) menu.popup() } @@ -428,6 +426,11 @@ class NoteList extends React.Component { }) } + handleDeleteNote (e, uniqueKey) { + this.handleNoteClick(e, uniqueKey) + ee.emit('detail:delete') + } + importFromFile () { const { dispatch, location } = this.props From 03fc45360895eb700fa8c32e3681150a9681143d Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Fri, 13 Oct 2017 14:05:10 +0900 Subject: [PATCH 13/17] Change method names --- browser/main/NoteList/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index f533b6bac..54e0d87a6 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -375,17 +375,17 @@ class NoteList extends React.Component { if (!location.pathname.match(/\/home|\/starred|\/trash/)) { menu.append(new MenuItem({ label: label, - click: (e) => this.handlePinToTop(e, uniqueKey) + click: (e) => this.pinToTop(e, uniqueKey) })) } menu.append(new MenuItem({ label: 'Delete Note', - click: (e) => this.handleDeleteNote(e, uniqueKey) + click: (e) => this.deleteNote(e, uniqueKey) })) menu.popup() } - handlePinToTop (e, uniqueKey) { + pinToTop (e, uniqueKey) { const { data, location } = this.props let splitted = location.pathname.split('/') const storageKey = splitted[2] @@ -426,7 +426,7 @@ class NoteList extends React.Component { }) } - handleDeleteNote (e, uniqueKey) { + deleteNote (e, uniqueKey) { this.handleNoteClick(e, uniqueKey) ee.emit('detail:delete') } From 9bca133d8899de9d567820f183191c3c686dcd25 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Fri, 13 Oct 2017 14:12:50 +0900 Subject: [PATCH 14/17] Remove updateFolder because it's no longer used --- browser/main/NoteList/index.js | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 54e0d87a6..2201f4f2c 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -386,32 +386,15 @@ class NoteList extends React.Component { } pinToTop (e, uniqueKey) { - const { data, location } = this.props - let splitted = location.pathname.split('/') - const storageKey = splitted[2] - const folderKey = splitted[4] + 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}) - 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 + const targetIndex = _.findIndex(this.notes, (note) => { + return note != null && `${note.storage}-${note.key}` === uniqueKey }) let note = this.notes[targetIndex] note.isPinned = !note.isPinned From f9b3284852c66a4cf75f622d16299ef5ed3f9686 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Fri, 13 Oct 2017 14:22:13 +0900 Subject: [PATCH 15/17] Fix a condition --- browser/main/NoteList/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 2201f4f2c..5c511233b 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -289,7 +289,7 @@ class NoteList extends React.Component { const storageKey = params.storageKey const folderKey = params.folderKey const storage = data.storageMap.get(storageKey) - if (location.pathname.match(/\/home|\/starred|\/trash/)) { + if (location.pathname.match(/\/home|\/starred|\/trash|\/search/)) { return unorderedNotes } if (storage === undefined) return [] From 2003bea3cff238ed11f0ffe5dbc1c66f75144b80 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Fri, 13 Oct 2017 16:24:13 +0900 Subject: [PATCH 16/17] Remove unnecessary lines --- browser/main/NoteList/index.js | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 5c511233b..be10d2060 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -252,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) } @@ -285,17 +285,6 @@ class NoteList extends React.Component { } sortByPin (unorderedNotes) { - const { data, params, location } = this.props - const storageKey = params.storageKey - const folderKey = params.folderKey - const storage = data.storageMap.get(storageKey) - if (location.pathname.match(/\/home|\/starred|\/trash|\/search/)) { - return unorderedNotes - } - if (storage === undefined) return [] - - const folder = _.find(storage.folders, {key: folderKey}) - if (folder === undefined) return unorderedNotes const pinnedNotes = unorderedNotes.filter((note) => { return note.isPinned }) From d274563b2c2e10bfe0f668fe5aa708c4e2adf4ba Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Fri, 13 Oct 2017 16:33:44 +0900 Subject: [PATCH 17/17] Change order for pinned notes on /home, /trashed, /searched or /starred --- browser/main/NoteList/index.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index be10d2060..90648426c 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -469,12 +469,13 @@ class NoteList extends React.Component { : config.sortBy === 'ALPHABETICAL' ? sortByAlphabetical : sortByUpdatedAt - const sortedNotes = this.getNotes().sort(sortFunc) - this.notes = notes = this.sortByPin(sortedNotes) - .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 => {