From 2d0e14c1cce1c10b57fa84de85d412e75213909f Mon Sep 17 00:00:00 2001 From: voidSatisfaction Date: Sun, 5 Nov 2017 18:11:08 +0900 Subject: [PATCH 01/12] feat: add shiftkey multiselect notes and delete --- browser/main/NoteList/index.js | 119 ++++++++++++++++++++++++++++++--- 1 file changed, 108 insertions(+), 11 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index c9e116d7..2e900790 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -15,6 +15,7 @@ import markdown from 'browser/lib/markdown' import { findNoteTitle } from 'browser/lib/findNoteTitle' import stripgtags from 'striptags' import store from 'browser/main/store' +import AwsMobileAnalyticsConfig from 'browser/main/lib/AwsMobileAnalyticsConfig' const { remote } = require('electron') const { Menu, MenuItem, dialog } = remote @@ -50,8 +51,12 @@ class NoteList extends React.Component { } this.importFromFileHandler = this.importFromFile.bind(this) this.jumpNoteByHash = this.jumpNoteByHashHandler.bind(this) + this.handleNoteListKeyUp = this.handleNoteListKeyUp.bind(this) + this.deleteNote = this.deleteNote.bind(this) this.state = { + shiftKeyDown: false, + selectedNoteIds: [] } this.contextNotes = [] @@ -197,6 +202,10 @@ class NoteList extends React.Component { } handleNoteListKeyDown (e) { + if (e.shiftKey) { + this.setState({ shiftKeyDown: true }) + } + if (e.metaKey || e.ctrlKey) return true if (e.keyCode === 65 && !e.shiftKey) { @@ -225,6 +234,12 @@ class NoteList extends React.Component { } } + handleNoteListKeyUp (e) { + if (!e.shiftKey) { + this.setState({ shiftKeyDown: false }) + } + } + getNotes () { let { data, params, location } = this.props let { router } = this.context @@ -302,13 +317,28 @@ class NoteList extends React.Component { handleNoteClick (e, uniqueKey) { let { router } = this.context let { location } = this.props + let { shiftKeyDown, selectedNoteIds } = this.state - router.push({ - pathname: location.pathname, - query: { - key: uniqueKey - } - }) + if (shiftKeyDown && !selectedNoteIds.includes(uniqueKey)) { + selectedNoteIds.push(uniqueKey) + this.setState({ + selectedNoteIds + }) + } else if (shiftKeyDown) { + this.setState({ + selectedNoteIds: [...selectedNoteIds].filter((item) => item !== uniqueKey) + }) + } else { + this.setState({ + selectedNoteIds: [uniqueKey] + }) + router.push({ + pathname: location.pathname, + query: { + key: uniqueKey + } + }) + } } handleSortByChange (e) { @@ -358,11 +388,16 @@ class NoteList extends React.Component { handleNoteContextMenu (e, uniqueKey) { const { location } = this.props + const { selectedNoteIds } = this.state const note = this.notes.find((note) => { const noteKey = `${note.storage}-${note.key}` return noteKey === uniqueKey }) + if (selectedNoteIds.length === 0) { + this.handleNoteClick(e, uniqueKey) + } + const pinLabel = note.isPinned ? 'Remove pin' : 'Pin to Top' const deleteLabel = 'Delete Note' @@ -375,7 +410,7 @@ class NoteList extends React.Component { } menu.append(new MenuItem({ label: deleteLabel, - click: (e) => this.deleteNote(e, uniqueKey) + click: this.deleteNote })) menu.popup() } @@ -403,9 +438,68 @@ class NoteList extends React.Component { }) } - deleteNote (e, uniqueKey) { - this.handleNoteClick(e, uniqueKey) - ee.emit('detail:delete') + deleteNote () { + const { dispatch } = this.props + const { selectedNoteIds } = this.state + // not to change objects of this.notes + const notes = this.notes.map((note) => Object.assign({}, note)) + const selectedNotes = notes.filter((note) => selectedNoteIds.includes(`${note.storage}-${note.key}`)) + const firstNote = selectedNotes[0] + + if (firstNote.isTrashed) { + const noteExp = selectedNotes.length > 1 ? 'notes' : 'note' + const dialogueButtonIndex = dialog.showMessageBox(remote.getCurrentWindow(), { + type: 'warning', + message: 'Confirm note deletion', + detail: `This will permanently remove ${selectedNotes.length} ${noteExp}.`, + buttons: ['Confirm', 'Cancel'] + }) + if (dialogueButtonIndex === 1) return + Promise.all( + selectedNoteIds.map((uniqueKey) => { + const storageKey = uniqueKey.split('-')[0] + const noteKey = uniqueKey.split('-')[1] + return dataApi + .deleteNote(storageKey, noteKey) + }) + ) + .then((data) => { + data.forEach((item) => { + dispatch({ + type: 'DELETE_NOTE', + storageKey: item.storageKey, + noteKey: item.noteKey + }) + }) + }) + .catch((err) => { + console.error('Cannot Delete note: ' + err) + }) + console.log('Notes were all deleted') + } else { + Promise.all( + selectedNotes.map((note) => { + note.isTrashed = true + + return dataApi + .updateNote(note.storage, note.key, note) + }) + ) + .then((newNotes) => { + newNotes.forEach((newNote) => { + dispatch({ + type: 'UPDATE_NOTE', + note: newNote + }) + }) + AwsMobileAnalyticsConfig.recordDynamicCustomEvent('EDIT_NOTE') + console.log('Notes went to trash') + }) + .catch((err) => { + console.error('Notes could not go to trash: ' + err) + }) + } + this.setState({ selectedNoteIds: [] }) } importFromFile () { @@ -475,6 +569,7 @@ class NoteList extends React.Component { render () { let { location, notes, config, dispatch } = this.props + let { selectedNoteIds } = this.state let sortFunc = config.sortBy === 'CREATED_AT' ? sortByCreatedAt : config.sortBy === 'ALPHABETICAL' @@ -495,7 +590,8 @@ class NoteList extends React.Component { } const isDefault = config.listStyle === 'DEFAULT' - const isActive = location.query.key === note.storage + '-' + note.key + const uniqueKey = note.storage + '-' + note.key + const isActive = selectedNoteIds.includes(uniqueKey) const dateDisplay = moment( config.sortBy === 'CREATED_AT' ? note.createdAt : note.updatedAt @@ -570,6 +666,7 @@ class NoteList extends React.Component { ref='list' tabIndex='-1' onKeyDown={(e) => this.handleNoteListKeyDown(e)} + onKeyUp={this.handleNoteListKeyUp} > {noteList} From a504a45d9907a2647fde74c9209bef69509853a4 Mon Sep 17 00:00:00 2001 From: voidSatisfaction Date: Sun, 5 Nov 2017 18:45:09 +0900 Subject: [PATCH 02/12] fix up and down key rendering problems --- browser/main/NoteList/index.js | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 2e900790..42e1f085 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -135,6 +135,7 @@ class NoteList extends React.Component { } let { router } = this.context let { location } = this.props + let { selectedNoteIds } = this.state let targetIndex = this.getTargetIndex() @@ -142,7 +143,15 @@ class NoteList extends React.Component { return } targetIndex-- - if (targetIndex < 0) targetIndex = 0 + + selectedNoteIds = [] + const priorNote = Object.assign({}, this.notes[targetIndex]) + const priorNoteKey = `${priorNote.storage}-${priorNote.key}` + selectedNoteIds.push(priorNoteKey) + + this.setState({ + selectedNoteIds + }) router.push({ pathname: location.pathname, @@ -158,6 +167,7 @@ class NoteList extends React.Component { } let { router } = this.context let { location } = this.props + let { selectedNoteIds } = this.state let targetIndex = this.getTargetIndex() @@ -169,6 +179,15 @@ class NoteList extends React.Component { else if (targetIndex > this.notes.length - 1) targetIndex === this.notes.length - 1 } + selectedNoteIds = [] + const nextNote = Object.assign({}, this.notes[targetIndex]) + const nextNoteKey = `${nextNote.storage}-${nextNote.key}` + selectedNoteIds.push(nextNoteKey) + + this.setState({ + selectedNoteIds + }) + router.push({ pathname: location.pathname, query: { @@ -202,10 +221,6 @@ class NoteList extends React.Component { } handleNoteListKeyDown (e) { - if (e.shiftKey) { - this.setState({ shiftKeyDown: true }) - } - if (e.metaKey || e.ctrlKey) return true if (e.keyCode === 65 && !e.shiftKey) { @@ -232,6 +247,10 @@ class NoteList extends React.Component { e.preventDefault() this.selectNextNote() } + + if (e.shiftKey) { + this.setState({ shiftKeyDown: true }) + } } handleNoteListKeyUp (e) { From a7e458b7848af1a50108f81868712dc1e8975471 Mon Sep 17 00:00:00 2001 From: voidSatisfaction Date: Sun, 5 Nov 2017 19:00:03 +0900 Subject: [PATCH 03/12] feat change name and add deletion logic --- browser/main/NoteList/index.js | 47 +++++++++++++++++----------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 42e1f085..1e21986e 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -56,7 +56,7 @@ class NoteList extends React.Component { this.state = { shiftKeyDown: false, - selectedNoteIds: [] + selectedNoteKeys: [] } this.contextNotes = [] @@ -135,7 +135,7 @@ class NoteList extends React.Component { } let { router } = this.context let { location } = this.props - let { selectedNoteIds } = this.state + let { selectedNoteKeys } = this.state let targetIndex = this.getTargetIndex() @@ -144,13 +144,13 @@ class NoteList extends React.Component { } targetIndex-- - selectedNoteIds = [] + selectedNoteKeys = [] const priorNote = Object.assign({}, this.notes[targetIndex]) const priorNoteKey = `${priorNote.storage}-${priorNote.key}` - selectedNoteIds.push(priorNoteKey) + selectedNoteKeys.push(priorNoteKey) this.setState({ - selectedNoteIds + selectedNoteKeys }) router.push({ @@ -167,7 +167,7 @@ class NoteList extends React.Component { } let { router } = this.context let { location } = this.props - let { selectedNoteIds } = this.state + let { selectedNoteKeys } = this.state let targetIndex = this.getTargetIndex() @@ -179,13 +179,13 @@ class NoteList extends React.Component { else if (targetIndex > this.notes.length - 1) targetIndex === this.notes.length - 1 } - selectedNoteIds = [] + selectedNoteKeys = [] const nextNote = Object.assign({}, this.notes[targetIndex]) const nextNoteKey = `${nextNote.storage}-${nextNote.key}` - selectedNoteIds.push(nextNoteKey) + selectedNoteKeys.push(nextNoteKey) this.setState({ - selectedNoteIds + selectedNoteKeys }) router.push({ @@ -336,20 +336,20 @@ class NoteList extends React.Component { handleNoteClick (e, uniqueKey) { let { router } = this.context let { location } = this.props - let { shiftKeyDown, selectedNoteIds } = this.state + let { shiftKeyDown, selectedNoteKeys } = this.state - if (shiftKeyDown && !selectedNoteIds.includes(uniqueKey)) { - selectedNoteIds.push(uniqueKey) + if (shiftKeyDown && !selectedNoteKeys.includes(uniqueKey)) { + selectedNoteKeys.push(uniqueKey) this.setState({ - selectedNoteIds + selectedNoteKeys }) } else if (shiftKeyDown) { this.setState({ - selectedNoteIds: [...selectedNoteIds].filter((item) => item !== uniqueKey) + selectedNoteKeys: [...selectedNoteKeys].filter((item) => item !== uniqueKey) }) } else { this.setState({ - selectedNoteIds: [uniqueKey] + selectedNoteKeys: [uniqueKey] }) router.push({ pathname: location.pathname, @@ -407,13 +407,14 @@ class NoteList extends React.Component { handleNoteContextMenu (e, uniqueKey) { const { location } = this.props - const { selectedNoteIds } = this.state + const { selectedNoteKeys } = this.state const note = this.notes.find((note) => { const noteKey = `${note.storage}-${note.key}` return noteKey === uniqueKey }) + const noteKey = `${note.storage}-${note.key}` - if (selectedNoteIds.length === 0) { + if (selectedNoteKeys.length === 0 || !selectedNoteKeys.includes(noteKey)) { this.handleNoteClick(e, uniqueKey) } @@ -459,10 +460,10 @@ class NoteList extends React.Component { deleteNote () { const { dispatch } = this.props - const { selectedNoteIds } = this.state + const { selectedNoteKeys } = this.state // not to change objects of this.notes const notes = this.notes.map((note) => Object.assign({}, note)) - const selectedNotes = notes.filter((note) => selectedNoteIds.includes(`${note.storage}-${note.key}`)) + const selectedNotes = notes.filter((note) => selectedNoteKeys.includes(`${note.storage}-${note.key}`)) const firstNote = selectedNotes[0] if (firstNote.isTrashed) { @@ -475,7 +476,7 @@ class NoteList extends React.Component { }) if (dialogueButtonIndex === 1) return Promise.all( - selectedNoteIds.map((uniqueKey) => { + selectedNoteKeys.map((uniqueKey) => { const storageKey = uniqueKey.split('-')[0] const noteKey = uniqueKey.split('-')[1] return dataApi @@ -518,7 +519,7 @@ class NoteList extends React.Component { console.error('Notes could not go to trash: ' + err) }) } - this.setState({ selectedNoteIds: [] }) + this.setState({ selectedNoteKeys: [] }) } importFromFile () { @@ -588,7 +589,7 @@ class NoteList extends React.Component { render () { let { location, notes, config, dispatch } = this.props - let { selectedNoteIds } = this.state + let { selectedNoteKeys } = this.state let sortFunc = config.sortBy === 'CREATED_AT' ? sortByCreatedAt : config.sortBy === 'ALPHABETICAL' @@ -610,7 +611,7 @@ class NoteList extends React.Component { const isDefault = config.listStyle === 'DEFAULT' const uniqueKey = note.storage + '-' + note.key - const isActive = selectedNoteIds.includes(uniqueKey) + const isActive = selectedNoteKeys.includes(uniqueKey) const dateDisplay = moment( config.sortBy === 'CREATED_AT' ? note.createdAt : note.updatedAt From 70b69a3bc9082dc0aa923508bce3037a1103f186 Mon Sep 17 00:00:00 2001 From: voidSatisfaction Date: Sun, 5 Nov 2017 19:22:55 +0900 Subject: [PATCH 04/12] refactor: inner codes --- browser/main/NoteList/index.js | 81 +++++++++++++++++----------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 1e21986e..067c25a3 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -53,6 +53,7 @@ class NoteList extends React.Component { this.jumpNoteByHash = this.jumpNoteByHashHandler.bind(this) this.handleNoteListKeyUp = this.handleNoteListKeyUp.bind(this) this.deleteNote = this.deleteNote.bind(this) + this.activateNote = this.activateNote.bind(this) this.state = { shiftKeyDown: false, @@ -129,6 +130,22 @@ class NoteList extends React.Component { } } + activateNote (selectedNoteKeys, noteKey) { + let { router } = this.context + let { location } = this.props + + this.setState({ + selectedNoteKeys + }) + + router.push({ + pathname: location.pathname, + query: { + key: noteKey + } + }) + } + selectPriorNote () { if (this.notes == null || this.notes.length === 0) { return @@ -149,16 +166,7 @@ class NoteList extends React.Component { const priorNoteKey = `${priorNote.storage}-${priorNote.key}` selectedNoteKeys.push(priorNoteKey) - this.setState({ - selectedNoteKeys - }) - - router.push({ - pathname: location.pathname, - query: { - key: this.notes[targetIndex].storage + '-' + this.notes[targetIndex].key - } - }) + this.activateNote(selectedNoteKeys, priorNoteKey) } selectNextNote () { @@ -184,16 +192,8 @@ class NoteList extends React.Component { const nextNoteKey = `${nextNote.storage}-${nextNote.key}` selectedNoteKeys.push(nextNoteKey) - this.setState({ - selectedNoteKeys - }) + this.activateNote(selectedNoteKeys, nextNoteKey) - router.push({ - pathname: location.pathname, - query: { - key: this.notes[targetIndex].storage + '-' + this.notes[targetIndex].key - } - }) ee.emit('list:moved') } @@ -210,12 +210,12 @@ class NoteList extends React.Component { if (targetIndex < 0) targetIndex = 0 - router.push({ - pathname: location.pathname, - query: { - key: this.notes[targetIndex].storage + '-' + this.notes[targetIndex].key - } - }) + selectedNoteKeys = [] + const nextNote = Object.assign({}, this.notes[targetIndex]) + const nextNoteKey = `${nextNote.storage}-${nextNote.key}` + selectedNoteKeys.push(nextNoteKey) + + this.activateNote(selectedNoteKeys, nextNoteKey) ee.emit('list:moved') } @@ -338,26 +338,25 @@ class NoteList extends React.Component { let { location } = this.props let { shiftKeyDown, selectedNoteKeys } = this.state - if (shiftKeyDown && !selectedNoteKeys.includes(uniqueKey)) { - selectedNoteKeys.push(uniqueKey) - this.setState({ - selectedNoteKeys - }) - } else if (shiftKeyDown) { + if (shiftKeyDown && selectedNoteKeys.includes(uniqueKey)) { this.setState({ selectedNoteKeys: [...selectedNoteKeys].filter((item) => item !== uniqueKey) }) - } else { - this.setState({ - selectedNoteKeys: [uniqueKey] - }) - router.push({ - pathname: location.pathname, - query: { - key: uniqueKey - } - }) + return } + if (!shiftKeyDown) { + selectedNoteKeys = [] + } + selectedNoteKeys.push(uniqueKey) + this.setState({ + selectedNoteKeys + }) + router.push({ + pathname: location.pathname, + query: { + key: uniqueKey + } + }) } handleSortByChange (e) { From bcb1fb4331f46c77a2a21dec3c9c1f283d31376c Mon Sep 17 00:00:00 2001 From: voidSatisfaction Date: Sun, 5 Nov 2017 21:18:39 +0900 Subject: [PATCH 05/12] feat multi drag and drop for changing folder --- browser/main/NoteList/index.js | 6 ++- browser/main/SideNav/StorageItem.js | 70 ++++++++++++++++------------- 2 files changed, 45 insertions(+), 31 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 067c25a3..975c28b5 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -400,8 +400,12 @@ class NoteList extends React.Component { } handleDragStart (e, note) { - const noteData = JSON.stringify(note) + const { selectedNoteKeys } = this.state + const notes = this.notes.map((note) => Object.assign({}, note)) + const selectedNotes = notes.filter((note) => selectedNoteKeys.includes(`${note.storage}-${note.key}`)) + const noteData = JSON.stringify(selectedNotes) e.dataTransfer.setData('note', noteData) + this.setState({ selectedNoteKeys: [] }) } handleNoteContextMenu (e, uniqueKey) { diff --git a/browser/main/SideNav/StorageItem.js b/browser/main/SideNav/StorageItem.js index c7985f75..ae84b539 100644 --- a/browser/main/SideNav/StorageItem.js +++ b/browser/main/SideNav/StorageItem.js @@ -142,40 +142,50 @@ class StorageItem extends React.Component { e.target.style.backgroundColor = e.dataTransfer.getData('defaultColor') } + dropNote (storage, folder, dispatch, location, noteData) { + noteData = noteData.filter((note) => folder.key !== note.folder) + const newNoteData = noteData.map((note) => Object.assign({}, note, {storage: storage, folder: folder.key})) + if (noteData.length === 0) return + + Promise.all( + newNoteData.map((note) => dataApi.createNote(storage.key, note)) + ) + .then((createdNoteData) => { + createdNoteData.forEach((note) => { + dispatch({ + type: 'UPDATE_NOTE', + note: note + }) + }) + }) + .catch((err) => { + console.error(`error on create notes: ${err}`) + }) + .then(() => { + return Promise.all( + noteData.map((note) => dataApi.deleteNote(note.storage, note.key)) + ) + }) + .then((deletedNoteData) => { + console.log(deletedNoteData) + deletedNoteData.forEach((note) => { + dispatch({ + type: 'DELETE_NOTE', + storageKey: note.storageKey, + noteKey: note.noteKey + }) + }) + }) + .catch((err) => { + console.error(`error on delete notes: ${err}`) + }) + } + handleDrop (e, storage, folder, dispatch, location) { e.target.style.opacity = '1' e.target.style.backgroundColor = e.dataTransfer.getData('defaultColor') const noteData = JSON.parse(e.dataTransfer.getData('note')) - const newNoteData = Object.assign({}, noteData, {storage: storage, folder: folder.key}) - if (folder.key === noteData.folder) return - dataApi - .createNote(storage.key, newNoteData) - .then((note) => { - dataApi - .deleteNote(noteData.storage, noteData.key) - .then((data) => { - let dispatchHandler = () => { - dispatch({ - type: 'DELETE_NOTE', - storageKey: data.storageKey, - noteKey: data.noteKey - }) - } - eventEmitter.once('list:moved', dispatchHandler) - eventEmitter.emit('list:next') - }) - .catch((err) => { - console.error(err) - }) - dispatch({ - type: 'UPDATE_NOTE', - note: note - }) - hashHistory.push({ - pathname: location.pathname, - query: {key: `${note.storage}-${note.key}`} - }) - }) + this.dropNote(storage, folder, dispatch, location, noteData) } render () { From 9139495f022d0956c5357d937145ffc25a639708 Mon Sep 17 00:00:00 2001 From: voidSatisfaction Date: Mon, 6 Nov 2017 21:53:31 +0900 Subject: [PATCH 06/12] feat: add multiple pin to top and rename activateNote to focusNote --- browser/main/NoteList/index.js | 44 ++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 975c28b5..77db18c8 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -53,8 +53,9 @@ class NoteList extends React.Component { this.jumpNoteByHash = this.jumpNoteByHashHandler.bind(this) this.handleNoteListKeyUp = this.handleNoteListKeyUp.bind(this) this.deleteNote = this.deleteNote.bind(this) - this.activateNote = this.activateNote.bind(this) + this.focusNote = this.focusNote.bind(this) + // TODO: not Selected noteKeys but SelectedNote(for reusing) this.state = { shiftKeyDown: false, selectedNoteKeys: [] @@ -130,7 +131,7 @@ class NoteList extends React.Component { } } - activateNote (selectedNoteKeys, noteKey) { + focusNote (selectedNoteKeys, noteKey) { let { router } = this.context let { location } = this.props @@ -166,7 +167,7 @@ class NoteList extends React.Component { const priorNoteKey = `${priorNote.storage}-${priorNote.key}` selectedNoteKeys.push(priorNoteKey) - this.activateNote(selectedNoteKeys, priorNoteKey) + this.focusNote(selectedNoteKeys, priorNoteKey) } selectNextNote () { @@ -192,7 +193,7 @@ class NoteList extends React.Component { const nextNoteKey = `${nextNote.storage}-${nextNote.key}` selectedNoteKeys.push(nextNoteKey) - this.activateNote(selectedNoteKeys, nextNoteKey) + this.focusNote(selectedNoteKeys, nextNoteKey) ee.emit('list:moved') } @@ -215,7 +216,7 @@ class NoteList extends React.Component { const nextNoteKey = `${nextNote.storage}-${nextNote.key}` selectedNoteKeys.push(nextNoteKey) - this.activateNote(selectedNoteKeys, nextNoteKey) + this.focusNote(selectedNoteKeys, nextNoteKey) ee.emit('list:moved') } @@ -439,26 +440,27 @@ class NoteList extends React.Component { } pinToTop (e, uniqueKey) { - const { data, params } = this.props - const storageKey = params.storageKey - const folderKey = params.folderKey + const { selectedNoteKeys } = this.state + const { dispatch } = this.props + const notes = this.notes.map((note) => Object.assign({}, note)) + const selectedNotes = notes.filter((note) => selectedNoteKeys.includes(`${note.storage}-${note.key}`)) - const currentStorage = data.storageMap.get(storageKey) - const currentFolder = _.find(currentStorage.folders, {key: folderKey}) - - this.handleNoteClick(e, uniqueKey) - const targetIndex = this.getTargetIndex() - let note = this.notes[targetIndex] - note.isPinned = !note.isPinned - - dataApi - .updateNote(note.storage, note.key, note) - .then((note) => { - store.dispatch({ + Promise.all( + selectedNotes.map((note) => { + note.isPinned = !note.isPinned + return dataApi + .updateNote(note.storage, note.key, note) + }) + ) + .then((updatedNotes) => { + updatedNotes.forEach((note) => { + dispatch({ type: 'UPDATE_NOTE', - note: note + note }) }) + }) + this.setState({ selectedNoteKeys: [] }) } deleteNote () { From 9095fe934dc4315e55bb32503cde1de53ee95a9a Mon Sep 17 00:00:00 2001 From: voidSatisfaction Date: Tue, 7 Nov 2017 00:01:50 +0900 Subject: [PATCH 07/12] add multi selection with arrow short cut --- browser/main/NoteList/index.js | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 77db18c8..7b2b4b16 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -153,7 +153,7 @@ class NoteList extends React.Component { } let { router } = this.context let { location } = this.props - let { selectedNoteKeys } = this.state + let { selectedNoteKeys, shiftKeyDown } = this.state let targetIndex = this.getTargetIndex() @@ -162,10 +162,16 @@ class NoteList extends React.Component { } targetIndex-- - selectedNoteKeys = [] + if (!shiftKeyDown) { + selectedNoteKeys = [] + } const priorNote = Object.assign({}, this.notes[targetIndex]) const priorNoteKey = `${priorNote.storage}-${priorNote.key}` - selectedNoteKeys.push(priorNoteKey) + if (selectedNoteKeys.includes(priorNoteKey)) { + selectedNoteKeys.pop() + } else { + selectedNoteKeys.push(priorNoteKey) + } this.focusNote(selectedNoteKeys, priorNoteKey) } @@ -176,11 +182,13 @@ class NoteList extends React.Component { } let { router } = this.context let { location } = this.props - let { selectedNoteKeys } = this.state + let { selectedNoteKeys, shiftKeyDown } = this.state let targetIndex = this.getTargetIndex() if (targetIndex === this.notes.length - 1) { + return + } else if (targetIndex === this.notes.length - 1) { targetIndex = 0 } else { targetIndex++ @@ -188,10 +196,16 @@ class NoteList extends React.Component { else if (targetIndex > this.notes.length - 1) targetIndex === this.notes.length - 1 } - selectedNoteKeys = [] + if (!shiftKeyDown) { + selectedNoteKeys = [] + } const nextNote = Object.assign({}, this.notes[targetIndex]) const nextNoteKey = `${nextNote.storage}-${nextNote.key}` - selectedNoteKeys.push(nextNoteKey) + if (selectedNoteKeys.includes(nextNoteKey)) { + selectedNoteKeys.pop() + } else { + selectedNoteKeys.push(nextNoteKey) + } this.focusNote(selectedNoteKeys, nextNoteKey) @@ -222,6 +236,7 @@ class NoteList extends React.Component { } handleNoteListKeyDown (e) { + const { shiftKeyDown } = this.state if (e.metaKey || e.ctrlKey) return true if (e.keyCode === 65 && !e.shiftKey) { @@ -231,7 +246,7 @@ class NoteList extends React.Component { if (e.keyCode === 68) { e.preventDefault() - ee.emit('detail:delete') + this.deleteNote() } if (e.keyCode === 69) { From e57fef24132b13047dd87b68f39ad4cff64a945e Mon Sep 17 00:00:00 2001 From: voidSatisfaction Date: Tue, 7 Nov 2017 22:38:28 +0900 Subject: [PATCH 08/12] refactor: add utils --- browser/main/NoteList/index.js | 57 +++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 7b2b4b16..afb99c23 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -32,6 +32,18 @@ function sortByUpdatedAt (a, b) { return new Date(b.updatedAt) - new Date(a.updatedAt) } +function findNoteByKey (notes, noteKey) { + return notes.find((note) => `${note.storage}-${note.key}` === noteKey) +} + +function findNotesByKeys (notes, noteKeys) { + return notes.filter((note) => noteKeys.includes(getNoteKey(note))) +} + +function getNoteKey (note) { + return `${note.storage}-${note.key}` +} + class NoteList extends React.Component { constructor (props) { super(props) @@ -162,9 +174,7 @@ class NoteList extends React.Component { } targetIndex-- - if (!shiftKeyDown) { - selectedNoteKeys = [] - } + if (!shiftKeyDown) { selectedNoteKeys = [] } const priorNote = Object.assign({}, this.notes[targetIndex]) const priorNoteKey = `${priorNote.storage}-${priorNote.key}` if (selectedNoteKeys.includes(priorNoteKey)) { @@ -174,6 +184,8 @@ class NoteList extends React.Component { } this.focusNote(selectedNoteKeys, priorNoteKey) + + ee.emit('list:moved') } selectNextNote () { @@ -186,7 +198,7 @@ class NoteList extends React.Component { let targetIndex = this.getTargetIndex() - if (targetIndex === this.notes.length - 1) { + if (targetIndex === this.notes.length - 1 && shiftKeyDown) { return } else if (targetIndex === this.notes.length - 1) { targetIndex = 0 @@ -196,11 +208,9 @@ class NoteList extends React.Component { else if (targetIndex > this.notes.length - 1) targetIndex === this.notes.length - 1 } - if (!shiftKeyDown) { - selectedNoteKeys = [] - } + if (!shiftKeyDown) { selectedNoteKeys = [] } const nextNote = Object.assign({}, this.notes[targetIndex]) - const nextNoteKey = `${nextNote.storage}-${nextNote.key}` + const nextNoteKey = getNoteKey(nextNote) if (selectedNoteKeys.includes(nextNoteKey)) { selectedNoteKeys.pop() } else { @@ -355,8 +365,9 @@ class NoteList extends React.Component { let { shiftKeyDown, selectedNoteKeys } = this.state if (shiftKeyDown && selectedNoteKeys.includes(uniqueKey)) { + const newSelectedNoteKeys = [...selectedNoteKeys].filter((noteKey) => noteKey !== uniqueKey) this.setState({ - selectedNoteKeys: [...selectedNoteKeys].filter((item) => item !== uniqueKey) + selectedNoteKeys: newSelectedNoteKeys }) return } @@ -367,6 +378,7 @@ class NoteList extends React.Component { this.setState({ selectedNoteKeys }) + router.push({ pathname: location.pathname, query: { @@ -418,7 +430,7 @@ class NoteList extends React.Component { handleDragStart (e, note) { const { selectedNoteKeys } = this.state const notes = this.notes.map((note) => Object.assign({}, note)) - const selectedNotes = notes.filter((note) => selectedNoteKeys.includes(`${note.storage}-${note.key}`)) + const selectedNotes = findNotesByKeys(notes, selectedNoteKeys) const noteData = JSON.stringify(selectedNotes) e.dataTransfer.setData('note', noteData) this.setState({ selectedNoteKeys: [] }) @@ -427,10 +439,7 @@ class NoteList extends React.Component { handleNoteContextMenu (e, uniqueKey) { const { location } = this.props const { selectedNoteKeys } = this.state - const note = this.notes.find((note) => { - const noteKey = `${note.storage}-${note.key}` - return noteKey === uniqueKey - }) + const note = findNoteByKey(this.notes, uniqueKey) const noteKey = `${note.storage}-${note.key}` if (selectedNoteKeys.length === 0 || !selectedNoteKeys.includes(noteKey)) { @@ -444,7 +453,7 @@ class NoteList extends React.Component { if (!location.pathname.match(/\/home|\/starred|\/trash/)) { menu.append(new MenuItem({ label: pinLabel, - click: (e) => this.pinToTop(e, uniqueKey) + click: this.pinToTop })) } menu.append(new MenuItem({ @@ -454,11 +463,11 @@ class NoteList extends React.Component { menu.popup() } - pinToTop (e, uniqueKey) { + pinToTop () { const { selectedNoteKeys } = this.state const { dispatch } = this.props const notes = this.notes.map((note) => Object.assign({}, note)) - const selectedNotes = notes.filter((note) => selectedNoteKeys.includes(`${note.storage}-${note.key}`)) + const selectedNotes = findNotesByKeys(notes, selectedNoteKeys) Promise.all( selectedNotes.map((note) => { @@ -481,9 +490,8 @@ class NoteList extends React.Component { deleteNote () { const { dispatch } = this.props const { selectedNoteKeys } = this.state - // not to change objects of this.notes const notes = this.notes.map((note) => Object.assign({}, note)) - const selectedNotes = notes.filter((note) => selectedNoteKeys.includes(`${note.storage}-${note.key}`)) + const selectedNotes = findNotesByKeys(notes, selectedNoteKeys) const firstNote = selectedNotes[0] if (firstNote.isTrashed) { @@ -592,7 +600,7 @@ class NoteList extends React.Component { }) hashHistory.push({ pathname: location.pathname, - query: {key: `${note.storage}-${note.key}`} + query: {key: getNoteKey(note)} }) }) }) @@ -602,7 +610,7 @@ class NoteList extends React.Component { getTargetIndex () { const { location } = this.props const targetIndex = _.findIndex(this.notes, (note) => { - return `${note.storage}-${note.key}` === location.query.key + return getNoteKey(note) === location.query.key }) return targetIndex } @@ -630,13 +638,12 @@ class NoteList extends React.Component { } const isDefault = config.listStyle === 'DEFAULT' - const uniqueKey = note.storage + '-' + note.key + const uniqueKey = getNoteKey(note) const isActive = selectedNoteKeys.includes(uniqueKey) const dateDisplay = moment( config.sortBy === 'CREATED_AT' ? note.createdAt : note.updatedAt ).fromNow() - const key = `${note.storage}-${note.key}` if (isDefault) { return ( @@ -644,7 +651,7 @@ class NoteList extends React.Component { isActive={isActive} note={note} dateDisplay={dateDisplay} - key={key} + key={uniqueKey} handleNoteContextMenu={this.handleNoteContextMenu.bind(this)} handleNoteClick={this.handleNoteClick.bind(this)} handleDragStart={this.handleDragStart.bind(this)} @@ -657,7 +664,7 @@ class NoteList extends React.Component { Date: Tue, 7 Nov 2017 22:47:08 +0900 Subject: [PATCH 09/12] resolve conflict with master --- 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 afb99c23..f394629b 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -643,7 +643,7 @@ class NoteList extends React.Component { const dateDisplay = moment( config.sortBy === 'CREATED_AT' ? note.createdAt : note.updatedAt - ).fromNow() + ).fromNow('D') if (isDefault) { return ( From 84f18ced475bbbc2c11af620e0fe7bb4893fb2f7 Mon Sep 17 00:00:00 2001 From: voidSatisfaction Date: Tue, 7 Nov 2017 23:07:39 +0900 Subject: [PATCH 10/12] fix: pintotop error --- browser/main/NoteList/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 0135e626..04ec9ff6 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -66,6 +66,7 @@ class NoteList extends React.Component { this.handleNoteListKeyUp = this.handleNoteListKeyUp.bind(this) this.deleteNote = this.deleteNote.bind(this) this.focusNote = this.focusNote.bind(this) + this.pinToTop = this.pinToTop.bind(this) // TODO: not Selected noteKeys but SelectedNote(for reusing) this.state = { From a36e779980c558de946a42c4af514ec3ed12883a Mon Sep 17 00:00:00 2001 From: voidSatisfaction Date: Wed, 15 Nov 2017 23:19:47 +0900 Subject: [PATCH 11/12] refactor: add new function and fix problems from feedbacks --- browser/main/NoteList/index.js | 33 +++++++++++++++++------------ browser/main/SideNav/StorageItem.js | 3 +-- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 04ec9ff6..545279af 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -64,6 +64,7 @@ class NoteList extends React.Component { this.importFromFileHandler = this.importFromFile.bind(this) this.jumpNoteByHash = this.jumpNoteByHashHandler.bind(this) this.handleNoteListKeyUp = this.handleNoteListKeyUp.bind(this) + this.getNoteKeyFromTargetIndex = this.getNoteKeyFromTargetIndex.bind(this) this.deleteNote = this.deleteNote.bind(this) this.focusNote = this.focusNote.bind(this) this.pinToTop = this.pinToTop.bind(this) @@ -145,8 +146,8 @@ class NoteList extends React.Component { } focusNote (selectedNoteKeys, noteKey) { - let { router } = this.context - let { location } = this.props + const { router } = this.context + const { location } = this.props this.setState({ selectedNoteKeys @@ -160,6 +161,12 @@ class NoteList extends React.Component { }) } + getNoteKeyFromTargetIndex (targetIndex) { + const note = Object.assign({}, this.notes[targetIndex]) + const noteKey = getNoteKey(note) + return noteKey + } + selectPriorNote () { if (this.notes == null || this.notes.length === 0) { return @@ -176,8 +183,7 @@ class NoteList extends React.Component { targetIndex-- if (!shiftKeyDown) { selectedNoteKeys = [] } - const priorNote = Object.assign({}, this.notes[targetIndex]) - const priorNoteKey = `${priorNote.storage}-${priorNote.key}` + const priorNoteKey = this.getNoteKeyFromTargetIndex(targetIndex) if (selectedNoteKeys.includes(priorNoteKey)) { selectedNoteKeys.pop() } else { @@ -198,20 +204,20 @@ class NoteList extends React.Component { let { selectedNoteKeys, shiftKeyDown } = this.state let targetIndex = this.getTargetIndex() + const isTargetLastNote = targetIndex === this.notes.length - 1 - if (targetIndex === this.notes.length - 1 && shiftKeyDown) { + if (isTargetLastNote && shiftKeyDown) { return - } else if (targetIndex === this.notes.length - 1) { + } else if (isTargetLastNote) { targetIndex = 0 } else { targetIndex++ if (targetIndex < 0) targetIndex = 0 - else if (targetIndex > this.notes.length - 1) targetIndex === this.notes.length - 1 + else if (targetIndex > this.notes.length - 1) targetIndex = this.notes.length - 1 } if (!shiftKeyDown) { selectedNoteKeys = [] } - const nextNote = Object.assign({}, this.notes[targetIndex]) - const nextNoteKey = getNoteKey(nextNote) + const nextNoteKey = this.getNoteKeyFromTargetIndex(targetIndex) if (selectedNoteKeys.includes(nextNoteKey)) { selectedNoteKeys.pop() } else { @@ -236,9 +242,8 @@ class NoteList extends React.Component { if (targetIndex < 0) targetIndex = 0 - selectedNoteKeys = [] - const nextNote = Object.assign({}, this.notes[targetIndex]) - const nextNoteKey = `${nextNote.storage}-${nextNote.key}` + const selectedNoteKeys = [] + const nextNoteKey = this.getNoteKeyFromTargetIndex(targetIndex) selectedNoteKeys.push(nextNoteKey) this.focusNote(selectedNoteKeys, nextNoteKey) @@ -366,7 +371,7 @@ class NoteList extends React.Component { let { shiftKeyDown, selectedNoteKeys } = this.state if (shiftKeyDown && selectedNoteKeys.includes(uniqueKey)) { - const newSelectedNoteKeys = [...selectedNoteKeys].filter((noteKey) => noteKey !== uniqueKey) + const newSelectedNoteKeys = selectedNoteKeys.filter((noteKey) => noteKey !== uniqueKey) this.setState({ selectedNoteKeys: newSelectedNoteKeys }) @@ -441,7 +446,7 @@ class NoteList extends React.Component { const { location } = this.props const { selectedNoteKeys } = this.state const note = findNoteByKey(this.notes, uniqueKey) - const noteKey = `${note.storage}-${note.key}` + const noteKey = getNoteKey(note) if (selectedNoteKeys.length === 0 || !selectedNoteKeys.includes(noteKey)) { this.handleNoteClick(e, uniqueKey) diff --git a/browser/main/SideNav/StorageItem.js b/browser/main/SideNav/StorageItem.js index ae84b539..407d23d2 100644 --- a/browser/main/SideNav/StorageItem.js +++ b/browser/main/SideNav/StorageItem.js @@ -144,8 +144,8 @@ class StorageItem extends React.Component { dropNote (storage, folder, dispatch, location, noteData) { noteData = noteData.filter((note) => folder.key !== note.folder) - const newNoteData = noteData.map((note) => Object.assign({}, note, {storage: storage, folder: folder.key})) if (noteData.length === 0) return + const newNoteData = noteData.map((note) => Object.assign({}, note, {storage: storage, folder: folder.key})) Promise.all( newNoteData.map((note) => dataApi.createNote(storage.key, note)) @@ -167,7 +167,6 @@ class StorageItem extends React.Component { ) }) .then((deletedNoteData) => { - console.log(deletedNoteData) deletedNoteData.forEach((note) => { dispatch({ type: 'DELETE_NOTE', From c33f9d830700b03c96a47453077574c0e6e1ae33 Mon Sep 17 00:00:00 2001 From: voidSatisfaction Date: Mon, 27 Nov 2017 14:31:11 +0900 Subject: [PATCH 12/12] fix: from let to const --- browser/main/NoteList/index.js | 37 ++++++++++++------------- browser/main/SideNav/StorageItem.js | 43 +++++++++++++++-------------- 2 files changed, 39 insertions(+), 41 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 545279af..5b9a59f8 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -1,4 +1,5 @@ -import React, { PropTypes } from 'react' +import PropTypes from 'prop-types' +import React from 'react' import CSSModules from 'browser/lib/CSSModules' import styles from './NoteList.styl' import moment from 'moment' @@ -13,7 +14,6 @@ import fs from 'fs' 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' import AwsMobileAnalyticsConfig from 'browser/main/lib/AwsMobileAnalyticsConfig' @@ -110,10 +110,10 @@ class NoteList extends React.Component { } componentDidUpdate (prevProps) { - let { location } = this.props + const { location } = this.props if (this.notes.length > 0 && location.query.key == null) { - let { router } = this.context + const { router } = this.context if (!location.pathname.match(/\/searched/)) this.contextNotes = this.getContextNotes() router.replace({ pathname: location.pathname, @@ -128,16 +128,16 @@ class NoteList extends React.Component { if (_.isString(location.query.key) && prevProps.location.query.key === location.query.key) { const targetIndex = this.getTargetIndex() if (targetIndex > -1) { - let list = this.refs.list - let item = list.childNodes[targetIndex] + const list = this.refs.list + const item = list.childNodes[targetIndex] if (item == null) return false - let overflowBelow = item.offsetTop + item.clientHeight - list.clientHeight - list.scrollTop > 0 + const overflowBelow = item.offsetTop + item.clientHeight - list.clientHeight - list.scrollTop > 0 if (overflowBelow) { list.scrollTop = item.offsetTop + item.clientHeight - list.clientHeight } - let overflowAbove = list.scrollTop > item.offsetTop + const overflowAbove = list.scrollTop > item.offsetTop if (overflowAbove) { list.scrollTop = item.offsetTop } @@ -292,8 +292,7 @@ class NoteList extends React.Component { } getNotes () { - let { data, params, location } = this.props - let { router } = this.context + const { data, params, location } = this.props if (location.pathname.match(/\/home/) || location.pathname.match(/\alltags/)) { const allNotes = data.noteMap.map((note) => note) @@ -394,9 +393,9 @@ class NoteList extends React.Component { } handleSortByChange (e) { - let { dispatch } = this.props + const { dispatch } = this.props - let config = { + const config = { sortBy: e.target.value } @@ -408,9 +407,9 @@ class NoteList extends React.Component { } handleListStyleButtonClick (e, style) { - let { dispatch } = this.props + const { dispatch } = this.props - let config = { + const config = { listStyle: style } @@ -557,8 +556,6 @@ class NoteList extends React.Component { } importFromFile () { - const { dispatch, location } = this.props - const options = { filters: [ { name: 'Documents', extensions: ['md', 'txt'] } @@ -623,7 +620,7 @@ class NoteList extends React.Component { // Find first storage if (storage == null) { - for (let kv of data.storageMap) { + for (const kv of data.storageMap) { storage = kv[1] break } @@ -682,7 +679,7 @@ class NoteList extends React.Component { } }) - let noteList = notes + const noteList = notes .map(note => { if (note == null) { return null @@ -749,7 +746,7 @@ class NoteList extends React.Component { } onClick={(e) => this.handleListStyleButtonClick(e, 'DEFAULT')} > - + diff --git a/browser/main/SideNav/StorageItem.js b/browser/main/SideNav/StorageItem.js index 407d23d2..579a0cb0 100644 --- a/browser/main/SideNav/StorageItem.js +++ b/browser/main/SideNav/StorageItem.js @@ -1,4 +1,5 @@ -import React, { PropTypes } from 'react' +import PropTypes from 'prop-types' +import React from 'react' import CSSModules from 'browser/lib/CSSModules' import styles from './StorageItem.styl' import { hashHistory } from 'react-router' @@ -22,7 +23,7 @@ class StorageItem extends React.Component { } handleHeaderContextMenu (e) { - let menu = new Menu() + const menu = new Menu() menu.append(new MenuItem({ label: 'Add Folder', click: (e) => this.handleAddFolderButtonClick(e) @@ -38,7 +39,7 @@ class StorageItem extends React.Component { } handleUnlinkStorageClick (e) { - let index = dialog.showMessageBox(remote.getCurrentWindow(), { + const index = dialog.showMessageBox(remote.getCurrentWindow(), { type: 'warning', message: 'Unlink Storage', detail: 'This work will just detatches a storage from Boostnote. (Any data won\'t be deleted.)', @@ -46,7 +47,7 @@ class StorageItem extends React.Component { }) if (index === 0) { - let { storage, dispatch } = this.props + const { storage, dispatch } = this.props dataApi.removeStorage(storage.key) .then(() => { dispatch({ @@ -67,7 +68,7 @@ class StorageItem extends React.Component { } handleAddFolderButtonClick (e) { - let { storage } = this.props + const { storage } = this.props modal.open(CreateFolderModal, { storage @@ -75,19 +76,19 @@ class StorageItem extends React.Component { } handleHeaderInfoClick (e) { - let { storage } = this.props + const { storage } = this.props hashHistory.push('/storages/' + storage.key) } handleFolderButtonClick (folderKey) { return (e) => { - let { storage } = this.props + const { storage } = this.props hashHistory.push('/storages/' + storage.key + '/folders/' + folderKey) } } handleFolderButtonContextMenu (e, folder) { - let menu = new Menu() + const menu = new Menu() menu.append(new MenuItem({ label: 'Rename Folder', click: (e) => this.handleRenameFolderClick(e, folder) @@ -103,7 +104,7 @@ class StorageItem extends React.Component { } handleRenameFolderClick (e, folder) { - let { storage } = this.props + const { storage } = this.props modal.open(RenameFolderModal, { storage, folder @@ -111,7 +112,7 @@ class StorageItem extends React.Component { } handleFolderDeleteClick (e, folder) { - let index = dialog.showMessageBox(remote.getCurrentWindow(), { + const index = dialog.showMessageBox(remote.getCurrentWindow(), { type: 'warning', message: 'Delete Folder', detail: 'This will delete all notes in the folder and can not be undone.', @@ -119,7 +120,7 @@ class StorageItem extends React.Component { }) if (index === 0) { - let { storage, dispatch } = this.props + const { storage, dispatch } = this.props dataApi .deleteFolder(storage.key, folder.key) .then((data) => { @@ -188,11 +189,11 @@ class StorageItem extends React.Component { } render () { - let { storage, location, isFolded, data, dispatch } = this.props - let { folderNoteMap, trashedSet } = data - let folderList = storage.folders.map((folder) => { - let isActive = !!(location.pathname.match(new RegExp('\/storages\/' + storage.key + '\/folders\/' + folder.key))) - let noteSet = folderNoteMap.get(storage.key + '-' + folder.key) + const { storage, location, isFolded, data, dispatch } = this.props + const { folderNoteMap, trashedSet } = data + const folderList = storage.folders.map((folder) => { + const isActive = !!(location.pathname.match(new RegExp('\/storages\/' + storage.key + '\/folders\/' + folder.key))) + const noteSet = folderNoteMap.get(storage.key + '-' + folder.key) let noteCount = 0 if (noteSet) { @@ -220,7 +221,7 @@ class StorageItem extends React.Component { ) }) - let isActive = location.pathname.match(new RegExp('\/storages\/' + storage.key + '$')) + const isActive = location.pathname.match(new RegExp('\/storages\/' + storage.key + '$')) return (
this.handleToggleButtonClick(e)} > - @@ -246,7 +247,7 @@ class StorageItem extends React.Component { }