Skip to content

Commit

Permalink
Merge pull request #1528 from Redsandro/selectionOnSearch
Browse files Browse the repository at this point in the history
UX: Keep selection synced with note visibility
  • Loading branch information
kazup01 authored Feb 19, 2018
2 parents 0cc793e + 5e07c7b commit 466844f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
17 changes: 15 additions & 2 deletions browser/main/NoteList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions browser/main/modals/NewNoteModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
Expand Down Expand Up @@ -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()
})
Expand Down

0 comments on commit 466844f

Please sign in to comment.