From 680eaa1d4ac448d2e8905983a47eafcfd11cf46d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=98=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2?= Date: Wed, 4 Jul 2018 13:33:47 +0300 Subject: [PATCH 1/4] Filtering displayed notes in Detail component --- browser/main/Detail/index.js | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/browser/main/Detail/index.js b/browser/main/Detail/index.js index 2c451085..3e6e450e 100644 --- a/browser/main/Detail/index.js +++ b/browser/main/Detail/index.js @@ -9,6 +9,7 @@ import ee from 'browser/main/lib/eventEmitter' import StatusBar from '../StatusBar' import i18n from 'browser/lib/i18n' import debounceRender from 'react-debounce-render' +import searchFromNotes from 'browser/lib/search' const OSX = global.process.platform === 'darwin' @@ -35,11 +36,38 @@ class Detail extends React.Component { } render () { - const { location, data, config } = this.props + const { location, data, params, config } = this.props let note = null if (location.query.key != null) { const noteKey = location.query.key - note = data.noteMap.get(noteKey) + let displayedNotes, noteKeys + + if (location.pathname.match(/\/home/) || location.pathname.match(/alltags/)) { + displayedNotes = data.noteMap.map(note => note) + } + if (location.pathname.match(/\/starred/)) { + displayedNotes = data.starredSet.toJS().map(uniqueKey => data.noteMap.get(uniqueKey)) + } + if (location.pathname.match(/\/searched/)) { + displayedNotes = searchFromNotes( + data.noteMap.map(note => note), + params.searchword + ) + } + if (location.pathname.match(/\/trashed/)) { + displayedNotes = data.trashedSet.toJS().map(uniqueKey => data.noteMap.get(uniqueKey)) + } + if (location.pathname.match(/\/tags/)) { + const listOfTags = params.tagname.split(' ') + displayedNotes = data.noteMap.map(note => note).filter(note => + listOfTags.every(tag => note.tags.includes(tag)) + ) + } + + noteKeys = displayedNotes.map(note => note.key) + if (noteKeys.includes(noteKey)) { + note = data.noteMap.get(noteKey) + } } if (note == null) { From c69be5465576691d1c37914d2cbc87944dd6ccb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=98=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2?= Date: Wed, 4 Jul 2018 14:02:26 +0300 Subject: [PATCH 2/4] Fixing empty string searching --- browser/main/Detail/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/browser/main/Detail/index.js b/browser/main/Detail/index.js index 3e6e450e..75a3f91a 100644 --- a/browser/main/Detail/index.js +++ b/browser/main/Detail/index.js @@ -40,7 +40,7 @@ class Detail extends React.Component { let note = null if (location.query.key != null) { const noteKey = location.query.key - let displayedNotes, noteKeys + let displayedNotes = [] if (location.pathname.match(/\/home/) || location.pathname.match(/alltags/)) { displayedNotes = data.noteMap.map(note => note) @@ -49,10 +49,10 @@ class Detail extends React.Component { displayedNotes = data.starredSet.toJS().map(uniqueKey => data.noteMap.get(uniqueKey)) } if (location.pathname.match(/\/searched/)) { - displayedNotes = searchFromNotes( - data.noteMap.map(note => note), - params.searchword - ) + const searchStr = params.searchword + const allNotes = data.noteMap.map(note => note) + displayedNotes = searchStr === undefined || searchStr === '' ? allNotes + : searchFromNotes(allNotes, searchStr) } if (location.pathname.match(/\/trashed/)) { displayedNotes = data.trashedSet.toJS().map(uniqueKey => data.noteMap.get(uniqueKey)) @@ -64,7 +64,7 @@ class Detail extends React.Component { ) } - noteKeys = displayedNotes.map(note => note.key) + const noteKeys = displayedNotes.map(note => note.key) if (noteKeys.includes(noteKey)) { note = data.noteMap.get(noteKey) } From 4a3602099a55bc6afe1f34269aa2cecbbf9986be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=98=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2?= Date: Wed, 4 Jul 2018 16:09:49 +0300 Subject: [PATCH 3/4] Difference home and searched notes from trashed units --- browser/main/Detail/index.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/browser/main/Detail/index.js b/browser/main/Detail/index.js index 75a3f91a..90edf10e 100644 --- a/browser/main/Detail/index.js +++ b/browser/main/Detail/index.js @@ -38,30 +38,43 @@ class Detail extends React.Component { render () { const { location, data, params, config } = this.props let note = null + + function differenceWithTrashed (notes) { + const trashedNotes = data.trashedSet.toJS().map(uniqueKey => data.noteMap.get(uniqueKey)) + return _.differenceWith(notes, trashedNotes, (note, trashed) => note.key === trashed.key) + } + if (location.query.key != null) { const noteKey = location.query.key let displayedNotes = [] if (location.pathname.match(/\/home/) || location.pathname.match(/alltags/)) { - displayedNotes = data.noteMap.map(note => note) + const allNotes = data.noteMap.map(note => note) + displayedNotes = differenceWithTrashed(allNotes) } + if (location.pathname.match(/\/starred/)) { displayedNotes = data.starredSet.toJS().map(uniqueKey => data.noteMap.get(uniqueKey)) } + if (location.pathname.match(/\/searched/)) { const searchStr = params.searchword const allNotes = data.noteMap.map(note => note) - displayedNotes = searchStr === undefined || searchStr === '' ? allNotes + const searchedNotes = searchStr === undefined || searchStr === '' ? allNotes : searchFromNotes(allNotes, searchStr) + displayedNotes = differenceWithTrashed(searchedNotes) } + if (location.pathname.match(/\/trashed/)) { displayedNotes = data.trashedSet.toJS().map(uniqueKey => data.noteMap.get(uniqueKey)) } + if (location.pathname.match(/\/tags/)) { const listOfTags = params.tagname.split(' ') - displayedNotes = data.noteMap.map(note => note).filter(note => + const searchedNotes = data.noteMap.map(note => note).filter(note => listOfTags.every(tag => note.tags.includes(tag)) ) + displayedNotes = differenceWithTrashed(searchedNotes) } const noteKeys = displayedNotes.map(note => note.key) From 806a5daa865a275452aa65e8b5f42c96029fd30c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=98=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2?= Date: Thu, 5 Jul 2018 11:23:57 +0300 Subject: [PATCH 4/4] Processing all location's pathnames --- browser/main/Detail/index.js | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/browser/main/Detail/index.js b/browser/main/Detail/index.js index 90edf10e..b6b6ef14 100644 --- a/browser/main/Detail/index.js +++ b/browser/main/Detail/index.js @@ -39,42 +39,29 @@ class Detail extends React.Component { const { location, data, params, config } = this.props let note = null - function differenceWithTrashed (notes) { - const trashedNotes = data.trashedSet.toJS().map(uniqueKey => data.noteMap.get(uniqueKey)) - return _.differenceWith(notes, trashedNotes, (note, trashed) => note.key === trashed.key) - } - if (location.query.key != null) { const noteKey = location.query.key - let displayedNotes = [] - - if (location.pathname.match(/\/home/) || location.pathname.match(/alltags/)) { - const allNotes = data.noteMap.map(note => note) - displayedNotes = differenceWithTrashed(allNotes) - } - - if (location.pathname.match(/\/starred/)) { - displayedNotes = data.starredSet.toJS().map(uniqueKey => data.noteMap.get(uniqueKey)) - } + const allNotes = data.noteMap.map(note => note) + const trashedNotes = data.trashedSet.toJS().map(uniqueKey => data.noteMap.get(uniqueKey)) + let displayedNotes = allNotes if (location.pathname.match(/\/searched/)) { const searchStr = params.searchword - const allNotes = data.noteMap.map(note => note) - const searchedNotes = searchStr === undefined || searchStr === '' ? allNotes + displayedNotes = searchStr === undefined || searchStr === '' ? allNotes : searchFromNotes(allNotes, searchStr) - displayedNotes = differenceWithTrashed(searchedNotes) - } - - if (location.pathname.match(/\/trashed/)) { - displayedNotes = data.trashedSet.toJS().map(uniqueKey => data.noteMap.get(uniqueKey)) } if (location.pathname.match(/\/tags/)) { const listOfTags = params.tagname.split(' ') - const searchedNotes = data.noteMap.map(note => note).filter(note => + displayedNotes = data.noteMap.map(note => note).filter(note => listOfTags.every(tag => note.tags.includes(tag)) ) - displayedNotes = differenceWithTrashed(searchedNotes) + } + + if (location.pathname.match(/\/trashed/)) { + displayedNotes = trashedNotes + } else { + displayedNotes = _.differenceWith(displayedNotes, trashedNotes, (note, trashed) => note.key === trashed.key) } const noteKeys = displayedNotes.map(note => note.key)