From 7b920348f3023f203bd32818691aa12e4622035b Mon Sep 17 00:00:00 2001 From: Sander Steenhuis Date: Sat, 10 Feb 2018 01:21:52 +0100 Subject: [PATCH 1/2] UX: Keep selection synced with note visibility --- browser/main/NoteList/index.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 30317095..bb583128 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -109,14 +109,27 @@ class NoteList extends React.Component { componentDidUpdate (prevProps) { const { location } = this.props + const { selectedNoteKeys } = this.state + const visibleNoteKeys = this.notes.map(note => `${note.storage}-${note.key}`) + const note = this.notes[0] + const prevKey = prevProps.location.query.key + const noteKey = visibleNoteKeys.includes(prevKey) ? prevKey : note && `${note.storage}-${note.key}` - if (this.notes.length > 0 && location.query.key == null) { + if (note && location.query.key == null) { const { router } = this.context if (!location.pathname.match(/\/searched/)) this.contextNotes = this.getContextNotes() + + // A visible note is an active note + if (!selectedNoteKeys.includes(noteKey)) { + if (selectedNoteKeys.length === 1) selectedNoteKeys.pop() + selectedNoteKeys.push(noteKey) + ee.emit('list:moved') + } + router.replace({ pathname: location.pathname, query: { - key: this.notes[0].storage + '-' + this.notes[0].key + key: noteKey } }) return From 5e07c7b3e1573cecabb917c10675cc0952b66bce Mon Sep 17 00:00:00 2001 From: Sander Steenhuis Date: Mon, 12 Feb 2018 18:15:05 +0100 Subject: [PATCH 2/2] Update selection on new note; closes #1507 --- browser/main/modals/NewNoteModal.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/browser/main/modals/NewNoteModal.js b/browser/main/modals/NewNoteModal.js index 24b150cb..8322d99f 100644 --- a/browser/main/modals/NewNoteModal.js +++ b/browser/main/modals/NewNoteModal.js @@ -35,14 +35,16 @@ class NewNoteModal extends React.Component { content: '' }) .then((note) => { + const noteHash = `${note.storage}-${note.key}` dispatch({ type: 'UPDATE_NOTE', note: note }) hashHistory.push({ pathname: location.pathname, - query: {key: note.storage + '-' + note.key} + query: {key: noteHash} }) + ee.emit('list:jump', noteHash) ee.emit('detail:focus') this.props.close() }) @@ -73,14 +75,16 @@ class NewNoteModal extends React.Component { }] }) .then((note) => { + const noteHash = `${note.storage}-${note.key}` dispatch({ type: 'UPDATE_NOTE', note: note }) hashHistory.push({ pathname: location.pathname, - query: {key: note.storage + '-' + note.key} + query: {key: noteHash} }) + ee.emit('list:jump', noteHash) ee.emit('detail:focus') this.props.close() })