1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

Cleanup, prettify

This commit is contained in:
bimlas
2018-04-10 22:05:22 +02:00
parent 61ed47dda0
commit 066d97220f
3 changed files with 22 additions and 29 deletions

View File

@@ -9,7 +9,9 @@ import CSSModules from 'browser/lib/CSSModules'
/** /**
* @param {string} name * @param {string} name
* @param {Function} handleClickTagListItem * @param {Function} handleClickTagListItem
* @param {Function} handleClickNarrowToTag
* @param {bool} isActive * @param {bool} isActive
* @param {bool} isRelated
*/ */
const TagListItem = ({name, handleClickTagListItem, handleClickNarrowToTag, isActive, isRelated, count}) => ( const TagListItem = ({name, handleClickTagListItem, handleClickNarrowToTag, isActive, isRelated, count}) => (

View File

@@ -346,9 +346,7 @@ class NoteList extends React.Component {
const listOfTags = params.tagname.split(' ') const listOfTags = params.tagname.split(' ')
return data.noteMap.map(note => { return data.noteMap.map(note => {
return note return note
}).filter(note => { }).filter(note => listOfTags.every(tag => note.tags.includes(tag)))
return listOfTags.every((tag) => note.tags.includes(tag))
})
} }
return this.getContextNotes() return this.getContextNotes()

View File

@@ -146,9 +146,9 @@ class SideNav extends React.Component {
tagListComponent () { tagListComponent () {
const { data, location, config } = this.props const { data, location, config } = this.props
const relatedTags = this.getRelatedTags(this.getActiveTags(location.pathname), data.noteMap) const relatedTags = this.getRelatedTags(this.getActiveTags(location.pathname), data.noteMap)
let tagList = _.sortBy(data.tagNoteMap.map((tag, name) => { let tagList = _.sortBy(data.tagNoteMap.map(
return { name, size: tag.size, related: relatedTags.has(name) } (tag, name) => ({ name, size: tag.size, related: relatedTags.has(name) })
}), ['name']) ), ['name'])
if (config.sortTagsBy === 'COUNTER') { if (config.sortTagsBy === 'COUNTER') {
tagList = _.sortBy(tagList, item => (0 - item.size)) tagList = _.sortBy(tagList, item => (0 - item.size))
} }
@@ -170,35 +170,29 @@ class SideNav extends React.Component {
} }
getRelatedTags (activeTags, noteMap) { getRelatedTags (activeTags, noteMap) {
if (activeTags.length == 0) { if (activeTags.length === 0) {
return new Set() return new Set()
} }
const relatedNotes = noteMap.map(note => { const relatedNotes = noteMap.map(
return {key: note.key, tags: note.tags} note => ({key: note.key, tags: note.tags})
}).filter((note) => { ).filter(
return activeTags.every((tag) => note.tags.includes(tag)) note => activeTags.every(tag => note.tags.includes(tag))
}) )
let relatedTags = new Set() let relatedTags = new Set()
relatedNotes.forEach(note => { relatedNotes.forEach(note => note.tags.map(tag => relatedTags.add(tag)))
note.tags.map(tag => {
relatedTags.add(tag)
})
})
return relatedTags return relatedTags
} }
getTagActive (path, tag) { getTagActive (path, tag) {
const pathTag = this.getActiveTags(path) return this.getActiveTags(path).includes(tag)
return pathTag.includes(tag)
} }
getActiveTags (path) { getActiveTags (path) {
const pathSegments = path.split('/') const pathSegments = path.split('/')
const tags = pathSegments[pathSegments.length - 1] const tags = pathSegments[pathSegments.length - 1]
if (tags === 'alltags') { return (tags === 'alltags')
return [] ? []
} : tags.split(' ')
return tags.split(' ')
} }
handleClickTagListItem (name) { handleClickTagListItem (name) {
@@ -220,16 +214,15 @@ class SideNav extends React.Component {
}) })
} }
handleClickNarrowToTag (name) { handleClickNarrowToTag (tag) {
const { router } = this.context const { router } = this.context
const { location } = this.props const { location } = this.props
let listOfTags = this.getActiveTags(location.pathname) let listOfTags = this.getActiveTags(location.pathname)
if (listOfTags.includes(name)) { const indexOfTag = listOfTags.indexOf(tag)
listOfTags = listOfTags.filter(function (currentTag) { if (indexOfTag > -1) {
return name !== currentTag listOfTags.splice(indexOfTag, 1)
})
} else { } else {
listOfTags.push(name) listOfTags.push(tag)
} }
router.push(`/tags/${listOfTags.join(' ')}`) router.push(`/tags/${listOfTags.join(' ')}`)
} }