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] 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)