1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 01:36:22 +00:00

Add per-folder sort

- save sort configuration in `config.[folderKey].sortBy`
- use lodash ` _.get(config, [folderKey, 'sortBy'])` to avoid error
This commit is contained in:
Mika Andrianarijaona
2018-08-11 11:36:36 +02:00
parent 79fb04126c
commit 47b0086bf8

View File

@@ -418,10 +418,10 @@ class NoteList extends React.Component {
} }
handleSortByChange (e) { handleSortByChange (e) {
const { dispatch } = this.props const { dispatch, params: { folderKey } } = this.props
const config = { const config = {
sortBy: e.target.value [folderKey]: { sortBy: e.target.value }
} }
ConfigManager.set(config) ConfigManager.set(config)
@@ -909,12 +909,12 @@ class NoteList extends React.Component {
} }
render () { render () {
const { location, config } = this.props const { location, config, params: { folderKey } } = this.props
let { notes } = this.props let { notes } = this.props
const { selectedNoteKeys } = this.state const { selectedNoteKeys } = this.state
const sortFunc = config.sortBy === 'CREATED_AT' const sortFunc = _.get(config, [folderKey, 'sortBy']) === 'CREATED_AT'
? sortByCreatedAt ? sortByCreatedAt
: config.sortBy === 'ALPHABETICAL' : _.get(config, [folderKey, 'sortBy']) === 'ALPHABETICAL'
? sortByAlphabetical ? sortByAlphabetical
: sortByUpdatedAt : sortByUpdatedAt
const sortedNotes = location.pathname.match(/\/starred|\/trash/) const sortedNotes = location.pathname.match(/\/starred|\/trash/)
@@ -965,7 +965,7 @@ class NoteList extends React.Component {
notes.length === 1 || notes.length === 1 ||
(autoSelectFirst && index === 0) (autoSelectFirst && index === 0)
const dateDisplay = moment( const dateDisplay = moment(
config.sortBy === 'CREATED_AT' _.get(config, [folderKey, 'sortBy']) === 'CREATED_AT'
? note.createdAt : note.updatedAt ? note.createdAt : note.updatedAt
).fromNow('D') ).fromNow('D')
@@ -1014,7 +1014,7 @@ class NoteList extends React.Component {
<i className='fa fa-angle-down' /> <i className='fa fa-angle-down' />
<select styleName='control-sortBy-select' <select styleName='control-sortBy-select'
title={i18n.__('Select filter mode')} title={i18n.__('Select filter mode')}
value={config.sortBy} value={_.get(config, [folderKey, 'sortBy'])}
onChange={(e) => this.handleSortByChange(e)} onChange={(e) => this.handleSortByChange(e)}
> >
<option title='Sort by update time' value='UPDATED_AT'>{i18n.__('Updated')}</option> <option title='Sort by update time' value='UPDATED_AT'>{i18n.__('Updated')}</option>