From 066d97220f53b58e7f8760c28f93262c6b532f8e Mon Sep 17 00:00:00 2001 From: bimlas Date: Tue, 10 Apr 2018 22:05:22 +0200 Subject: [PATCH] Cleanup, prettify --- browser/components/TagListItem.js | 2 ++ browser/main/NoteList/index.js | 4 +-- browser/main/SideNav/index.js | 45 +++++++++++++------------------ 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/browser/components/TagListItem.js b/browser/components/TagListItem.js index 196a5a23..2d0b6777 100644 --- a/browser/components/TagListItem.js +++ b/browser/components/TagListItem.js @@ -9,7 +9,9 @@ import CSSModules from 'browser/lib/CSSModules' /** * @param {string} name * @param {Function} handleClickTagListItem +* @param {Function} handleClickNarrowToTag * @param {bool} isActive +* @param {bool} isRelated */ const TagListItem = ({name, handleClickTagListItem, handleClickNarrowToTag, isActive, isRelated, count}) => ( diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index def289fb..e8c09f65 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -346,9 +346,7 @@ class NoteList extends React.Component { const listOfTags = params.tagname.split(' ') return data.noteMap.map(note => { return note - }).filter(note => { - return listOfTags.every((tag) => note.tags.includes(tag)) - }) + }).filter(note => listOfTags.every(tag => note.tags.includes(tag))) } return this.getContextNotes() diff --git a/browser/main/SideNav/index.js b/browser/main/SideNav/index.js index 2a6d34ce..8f0948c9 100644 --- a/browser/main/SideNav/index.js +++ b/browser/main/SideNav/index.js @@ -146,9 +146,9 @@ class SideNav extends React.Component { tagListComponent () { const { data, location, config } = this.props const relatedTags = this.getRelatedTags(this.getActiveTags(location.pathname), data.noteMap) - let tagList = _.sortBy(data.tagNoteMap.map((tag, name) => { - return { name, size: tag.size, related: relatedTags.has(name) } - }), ['name']) + let tagList = _.sortBy(data.tagNoteMap.map( + (tag, name) => ({ name, size: tag.size, related: relatedTags.has(name) }) + ), ['name']) if (config.sortTagsBy === 'COUNTER') { tagList = _.sortBy(tagList, item => (0 - item.size)) } @@ -170,35 +170,29 @@ class SideNav extends React.Component { } getRelatedTags (activeTags, noteMap) { - if (activeTags.length == 0) { + if (activeTags.length === 0) { return new Set() } - const relatedNotes = noteMap.map(note => { - return {key: note.key, tags: note.tags} - }).filter((note) => { - return activeTags.every((tag) => note.tags.includes(tag)) - }) + const relatedNotes = noteMap.map( + note => ({key: note.key, tags: note.tags}) + ).filter( + note => activeTags.every(tag => note.tags.includes(tag)) + ) let relatedTags = new Set() - relatedNotes.forEach(note => { - note.tags.map(tag => { - relatedTags.add(tag) - }) - }) + relatedNotes.forEach(note => note.tags.map(tag => relatedTags.add(tag))) return relatedTags } getTagActive (path, tag) { - const pathTag = this.getActiveTags(path) - return pathTag.includes(tag) + return this.getActiveTags(path).includes(tag) } getActiveTags (path) { const pathSegments = path.split('/') const tags = pathSegments[pathSegments.length - 1] - if (tags === 'alltags') { - return [] - } - return tags.split(' ') + return (tags === 'alltags') + ? [] + : tags.split(' ') } handleClickTagListItem (name) { @@ -220,16 +214,15 @@ class SideNav extends React.Component { }) } - handleClickNarrowToTag (name) { + handleClickNarrowToTag (tag) { const { router } = this.context const { location } = this.props let listOfTags = this.getActiveTags(location.pathname) - if (listOfTags.includes(name)) { - listOfTags = listOfTags.filter(function (currentTag) { - return name !== currentTag - }) + const indexOfTag = listOfTags.indexOf(tag) + if (indexOfTag > -1) { + listOfTags.splice(indexOfTag, 1) } else { - listOfTags.push(name) + listOfTags.push(tag) } router.push(`/tags/${listOfTags.join(' ')}`) }