mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
Merge pull request #1742 from bimlas/order-of-tags
Add selector to sort tags by counter or alphabetically
This commit is contained in:
@@ -82,7 +82,7 @@ class SideNav extends React.Component {
|
||||
}
|
||||
|
||||
SideNavComponent (isFolded, storageList) {
|
||||
const { location, data } = this.props
|
||||
const { location, data, config } = this.props
|
||||
|
||||
const isHomeActive = !!location.pathname.match(/^\/home$/)
|
||||
const isStarredActive = !!location.pathname.match(/^\/starred$/)
|
||||
@@ -115,8 +115,23 @@ class SideNav extends React.Component {
|
||||
} else {
|
||||
component = (
|
||||
<div styleName='tabBody'>
|
||||
<div styleName='tag-title'>
|
||||
<p>{i18n.__('Tags')}</p>
|
||||
<div styleName='tag-control'>
|
||||
<div styleName='tag-control-title'>
|
||||
<p>{i18n.__('Tags')}</p>
|
||||
</div>
|
||||
<div styleName='tag-control-sortTagsBy'>
|
||||
<i className='fa fa-angle-down' />
|
||||
<select styleName='tag-control-sortTagsBy-select'
|
||||
title={i18n.__('Select filter mode')}
|
||||
value={config.sortTagsBy}
|
||||
onChange={(e) => this.handleSortTagsByChange(e)}
|
||||
>
|
||||
<option title='Sort alphabetically'
|
||||
value='ALPHABETICAL'>{i18n.__('Alphabetically')}</option>
|
||||
<option title='Sort by update time'
|
||||
value='COUNTER'>{i18n.__('Counter')}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div styleName='tagList'>
|
||||
{this.tagListComponent(data)}
|
||||
@@ -129,10 +144,14 @@ class SideNav extends React.Component {
|
||||
}
|
||||
|
||||
tagListComponent () {
|
||||
const { data, location } = this.props
|
||||
const tagList = _.sortBy(data.tagNoteMap.map((tag, name) => {
|
||||
return { name, size: tag.size }
|
||||
}), ['name'])
|
||||
const { data, location, config } = this.props
|
||||
let tagList = _.sortBy(data.tagNoteMap.map(
|
||||
(tag, name) => ({name, size: tag.size})),
|
||||
['name']
|
||||
)
|
||||
if (config.sortTagsBy === 'COUNTER') {
|
||||
tagList = _.sortBy(tagList, item => (0 - item.size))
|
||||
}
|
||||
return (
|
||||
tagList.map(tag => {
|
||||
return (
|
||||
@@ -159,6 +178,20 @@ class SideNav extends React.Component {
|
||||
router.push(`/tags/${name}`)
|
||||
}
|
||||
|
||||
handleSortTagsByChange (e) {
|
||||
const { dispatch } = this.props
|
||||
|
||||
const config = {
|
||||
sortTagsBy: e.target.value
|
||||
}
|
||||
|
||||
ConfigManager.set(config)
|
||||
dispatch({
|
||||
type: 'SET_CONFIG',
|
||||
config
|
||||
})
|
||||
}
|
||||
|
||||
emptyTrash (entries) {
|
||||
const { dispatch } = this.props
|
||||
const deletionPromises = entries.map((note) => {
|
||||
|
||||
Reference in New Issue
Block a user