Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions browser/components/TagListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,26 @@ 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, isActive, count}) => (
<button styleName={isActive ? 'tagList-item-active' : 'tagList-item'} onClick={() => handleClickTagListItem(name)}>
<span styleName='tagList-item-name'>
{`# ${name}`}
<span styleName='tagList-item-count'>{count}</span>
</span>
</button>
const TagListItem = ({name, handleClickTagListItem, handleClickNarrowToTag, isActive, isRelated, count}) => (
<div styleName='tagList-itemContainer'>
{isRelated
? <button styleName={isActive ? 'tagList-itemNarrow-active' : 'tagList-itemNarrow'} onClick={() => handleClickNarrowToTag(name)}>
<i className={isActive ? 'fa fa-minus-circle' : 'fa fa-plus-circle'} />
</button>
: <div styleName={isActive ? 'tagList-itemNarrow-active' : 'tagList-itemNarrow'} />
}
<button styleName={isActive ? 'tagList-item-active' : 'tagList-item'} onClick={() => handleClickTagListItem(name)}>
<span styleName='tagList-item-name'>
{`# ${name}`}
<span styleName='tagList-item-count'>{count}</span>
</span>
</button>
</div>
)

TagListItem.propTypes = {
Expand Down
19 changes: 18 additions & 1 deletion browser/components/TagListItem.styl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
.tagList-itemContainer
display flex

.tagList-item
display flex
flex 1
width 100%
height 26px
background-color transparent
Expand All @@ -20,9 +24,16 @@
color $ui-button-default-color
background-color $ui-button-default--active-backgroundColor

.tagList-itemNarrow
composes tagList-item
flex none
width 20px
padding 0 4px

.tagList-item-active
background-color $ui-button-default--active-backgroundColor
display flex
flex 1
width 100%
height 26px
padding 0
Expand All @@ -36,10 +47,16 @@
background-color alpha($ui-button-default--active-backgroundColor, 60%)
transition 0.2s

.tagList-itemNarrow-active
composes tagList-item-active
flex none
width 20px
padding 0 4px

.tagList-item-name
display block
flex 1
padding 0 15px
padding 0 8px 0 4px
height 26px
line-height 26px
border-width 0 0 0 2px
Expand Down
5 changes: 2 additions & 3 deletions browser/main/NoteList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,10 @@ class NoteList extends React.Component {
}

if (location.pathname.match(/\/tags/)) {
const listOfTags = params.tagname.split(' ')
return data.noteMap.map(note => {
return note
}).filter(note => {
return note.tags.includes(params.tagname)
})
}).filter(note => listOfTags.every(tag => note.tags.includes(tag)))
}

return this.getContextNotes()
Expand Down
50 changes: 45 additions & 5 deletions browser/main/SideNav/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,27 @@ 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) => ({name, size: tag.size})),
['name']
)
(tag, name) => ({ name, size: tag.size, related: relatedTags.has(name) })
), ['name'])
if (config.sortTagsBy === 'COUNTER') {
tagList = _.sortBy(tagList, item => (0 - item.size))
}
if (config.ui.showOnlyRelatedTags && (relatedTags.size > 0)) {
tagList = tagList.filter(
tag => tag.related
)
}
return (
tagList.map(tag => {
return (
<TagListItem
name={tag.name}
handleClickTagListItem={this.handleClickTagListItem.bind(this)}
handleClickNarrowToTag={this.handleClickNarrowToTag.bind(this)}
isActive={this.getTagActive(location.pathname, tag.name)}
isRelated={tag.related}
key={tag.name}
count={tag.size}
/>
Expand All @@ -167,10 +174,30 @@ class SideNav extends React.Component {
)
}

getRelatedTags (activeTags, noteMap) {
if (activeTags.length === 0) {
return new Set()
}
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)))
return relatedTags
}

getTagActive (path, tag) {
return this.getActiveTags(path).includes(tag)
}

getActiveTags (path) {
const pathSegments = path.split('/')
const pathTag = pathSegments[pathSegments.length - 1]
return pathTag === tag
const tags = pathSegments[pathSegments.length - 1]
return (tags === 'alltags')
? []
: tags.split(' ')
}

handleClickTagListItem (name) {
Expand All @@ -192,6 +219,19 @@ class SideNav extends React.Component {
})
}

handleClickNarrowToTag (tag) {
const { router } = this.context
const { location } = this.props
let listOfTags = this.getActiveTags(location.pathname)
const indexOfTag = listOfTags.indexOf(tag)
if (indexOfTag > -1) {
listOfTags.splice(indexOfTag, 1)
} else {
listOfTags.push(tag)
}
router.push(`/tags/${listOfTags.join(' ')}`)
}

emptyTrash (entries) {
const { dispatch } = this.props
const deletionPromises = entries.map((note) => {
Expand Down
11 changes: 11 additions & 0 deletions browser/main/modals/PreferencesModal/UiTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class UiTab extends React.Component {
language: this.refs.uiLanguage.value,
showCopyNotification: this.refs.showCopyNotification.checked,
confirmDeletion: this.refs.confirmDeletion.checked,
showOnlyRelatedTags: this.refs.showOnlyRelatedTags.checked,
disableDirectWrite: this.refs.uiD2w != null
? this.refs.uiD2w.checked
: false
Expand Down Expand Up @@ -210,6 +211,16 @@ class UiTab extends React.Component {
{i18n.__('Show a confirmation dialog when deleting notes')}
</label>
</div>
<div styleName='group-checkBoxSection'>
<label>
<input onChange={(e) => this.handleUIChange(e)}
checked={this.state.config.ui.showOnlyRelatedTags}
ref='showOnlyRelatedTags'
type='checkbox'
/>&nbsp;
{i18n.__('Show only related tags')}
</label>
</div>
{
global.process.platform === 'win32'
? <div styleName='group-checkBoxSection'>
Expand Down
27 changes: 17 additions & 10 deletions tests/components/__snapshots__/TagListItem.snapshot.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`TagListItem renders correctly 1`] = `
<button
className="tagList-item"
onClick={[Function]}
<div
className="tagList-itemContainer"
>
<span
className="tagList-item-name"
<div
className="tagList-itemNarrow"
/>
<button
className="tagList-item"
onClick={[Function]}
>
# Test
<span
className="tagList-item-count"
className="tagList-item-name"
>

# Test
<span
className="tagList-item-count"
>

</span>
</span>
</span>
</button>
</button>
</div>
`;