Skip to content

Commit d706a53

Browse files
AlexGarrityRokt33r
authored andcommitted
Added sorting direction buttons
1 parent feb2a87 commit d706a53

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

browser/main/NoteList/index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,20 @@ class NoteList extends React.Component {
581581
})
582582
}
583583

584+
handleListDirectionButtonClick(e, direction) {
585+
const { dispatch } = this.props
586+
587+
const config = {
588+
listDirection: direction
589+
}
590+
591+
ConfigManager.set(config)
592+
dispatch({
593+
type: 'SET_CONFIG',
594+
config
595+
})
596+
}
597+
584598
alertIfSnippet(msg) {
585599
const warningMessage = msg =>
586600
({
@@ -1120,6 +1134,7 @@ class NoteList extends React.Component {
11201134
let { notes } = this.props
11211135
const { selectedNoteKeys } = this.state
11221136
const sortBy = _.get(config, [folderKey, 'sortBy'], config.sortBy.default)
1137+
const sortDir = config.listDirection
11231138
const sortFunc =
11241139
sortBy === 'CREATED_AT'
11251140
? sortByCreatedAt
@@ -1129,6 +1144,7 @@ class NoteList extends React.Component {
11291144
const sortedNotes = location.pathname.match(/\/starred|\/trash/)
11301145
? this.getNotes().sort(sortFunc)
11311146
: this.sortByPin(this.getNotes().sort(sortFunc))
1147+
if (sortDir === 'DESCENDING') sortedNotes.reverse()
11321148
this.notes = notes = sortedNotes.filter(note => {
11331149
// this is for the trash box
11341150
if (note.isTrashed !== true || location.pathname === '/trashed')
@@ -1241,6 +1257,30 @@ class NoteList extends React.Component {
12411257
</select>
12421258
</div>
12431259
<div styleName='control-button-area'>
1260+
<button
1261+
title={i18n.__('Ascending Order')}
1262+
styleName={
1263+
config.listDirection === 'ASCENDING'
1264+
? 'control-button--active'
1265+
: 'control-button'
1266+
}
1267+
onClick={e => this.handleListDirectionButtonClick(e, 'ASCENDING')}
1268+
>
1269+
<img src='../resources/icon/icon-up.svg' />
1270+
</button>
1271+
<button
1272+
title={i18n.__('Descending Order')}
1273+
styleName={
1274+
config.listDirection === 'DESCENDING'
1275+
? 'control-button--active'
1276+
: 'control-button'
1277+
}
1278+
onClick={e =>
1279+
this.handleListDirectionButtonClick(e, 'DESCENDING')
1280+
}
1281+
>
1282+
<img src='../resources/icon/icon-down.svg' />
1283+
</button>
12441284
<button
12451285
title={i18n.__('Default View')}
12461286
styleName={

browser/main/lib/ConfigManager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const DEFAULT_CONFIG = {
2727
},
2828
sortTagsBy: 'ALPHABETICAL', // 'ALPHABETICAL', 'COUNTER'
2929
listStyle: 'DEFAULT', // 'DEFAULT', 'SMALL'
30+
listDirection: 'ASCENDING', // 'ASCENDING', 'DESCENDING'
3031
amaEnabled: true,
3132
autoUpdateEnabled: true,
3233
hotkey: {

resources/icon/icon-up.svg

Lines changed: 17 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)