From 47b0086bf8e840d4c89211dfe0c88ff300d4c13c Mon Sep 17 00:00:00 2001 From: Mika Andrianarijaona Date: Sat, 11 Aug 2018 11:36:36 +0200 Subject: [PATCH 1/3] Add per-folder sort - save sort configuration in `config.[folderKey].sortBy` - use lodash ` _.get(config, [folderKey, 'sortBy'])` to avoid error --- browser/main/NoteList/index.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index eeb16a5f..23e3fb77 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -418,10 +418,10 @@ class NoteList extends React.Component { } handleSortByChange (e) { - const { dispatch } = this.props + const { dispatch, params: { folderKey } } = this.props const config = { - sortBy: e.target.value + [folderKey]: { sortBy: e.target.value } } ConfigManager.set(config) @@ -909,12 +909,12 @@ class NoteList extends React.Component { } render () { - const { location, config } = this.props + const { location, config, params: { folderKey } } = this.props let { notes } = this.props const { selectedNoteKeys } = this.state - const sortFunc = config.sortBy === 'CREATED_AT' + const sortFunc = _.get(config, [folderKey, 'sortBy']) === 'CREATED_AT' ? sortByCreatedAt - : config.sortBy === 'ALPHABETICAL' + : _.get(config, [folderKey, 'sortBy']) === 'ALPHABETICAL' ? sortByAlphabetical : sortByUpdatedAt const sortedNotes = location.pathname.match(/\/starred|\/trash/) @@ -965,7 +965,7 @@ class NoteList extends React.Component { notes.length === 1 || (autoSelectFirst && index === 0) const dateDisplay = moment( - config.sortBy === 'CREATED_AT' + _.get(config, [folderKey, 'sortBy']) === 'CREATED_AT' ? note.createdAt : note.updatedAt ).fromNow('D') @@ -1014,7 +1014,7 @@ class NoteList extends React.Component { this.handleSortByChange(e)} > From 9572cb2d33a0cf3910636d227f19c821977acc15 Mon Sep 17 00:00:00 2001 From: Mika Andrianarijaona Date: Sun, 12 Aug 2018 09:21:46 +0200 Subject: [PATCH 3/3] Fix default value of config.sortBy --- .boostnoterc.sample | 4 +++- browser/main/NoteList/index.js | 2 +- browser/main/lib/ConfigManager.js | 4 +++- tests/lib/rc-parser-test.js | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.boostnoterc.sample b/.boostnoterc.sample index a7981f7f..2d581a48 100644 --- a/.boostnoterc.sample +++ b/.boostnoterc.sample @@ -22,7 +22,9 @@ "fontSize": "14", "lineNumber": true }, - "sortBy": "UPDATED_AT", + "sortBy": { + "default": "UPDATED_AT" + }, "sortTagsBy": "ALPHABETICAL", "ui": { "defaultNote": "ALWAYS_ASK", diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 94b32f4c..f7dd0764 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -912,7 +912,7 @@ class NoteList extends React.Component { const { location, config, params: { folderKey } } = this.props let { notes } = this.props const { selectedNoteKeys } = this.state - const sortBy = _.get(config, [folderKey, 'sortBy'], config.sortBy) + const sortBy = _.get(config, [folderKey, 'sortBy'], config.sortBy.default) const sortFunc = sortBy === 'CREATED_AT' ? sortByCreatedAt : sortBy === 'ALPHABETICAL' diff --git a/browser/main/lib/ConfigManager.js b/browser/main/lib/ConfigManager.js index 0f6264be..434b0d22 100644 --- a/browser/main/lib/ConfigManager.js +++ b/browser/main/lib/ConfigManager.js @@ -16,7 +16,9 @@ export const DEFAULT_CONFIG = { isSideNavFolded: false, listWidth: 280, navWidth: 200, - sortBy: 'UPDATED_AT', // 'CREATED_AT', 'UPDATED_AT', 'APLHABETICAL' + sortBy: { + default: 'UPDATED_AT' // 'CREATED_AT', 'UPDATED_AT', 'APLHABETICAL' + }, sortTagsBy: 'ALPHABETICAL', // 'ALPHABETICAL', 'COUNTER' listStyle: 'DEFAULT', // 'DEFAULT', 'SMALL' amaEnabled: true, diff --git a/tests/lib/rc-parser-test.js b/tests/lib/rc-parser-test.js index 21d70d3c..024a2d36 100644 --- a/tests/lib/rc-parser-test.js +++ b/tests/lib/rc-parser-test.js @@ -5,7 +5,7 @@ const { parse } = require('browser/lib/RcParser') // Unit test test('RcParser should return a json object', t => { const validJson = { 'editor': { 'keyMap': 'vim', 'switchPreview': 'BLUR', 'theme': 'monokai' }, 'hotkey': { 'toggleMain': 'Control + L' }, 'listWidth': 135, 'navWidth': 135 } - const allJson = { 'amaEnabled': true, 'editor': { 'fontFamily': 'Monaco, Consolas', 'fontSize': '14', 'indentSize': '2', 'indentType': 'space', 'keyMap': 'vim', 'switchPreview': 'BLUR', 'theme': 'monokai' }, 'hotkey': { 'toggleMain': 'Cmd + Alt + L' }, 'isSideNavFolded': false, 'listStyle': 'DEFAULT', 'listWidth': 174, 'navWidth': 200, 'preview': { 'codeBlockTheme': 'dracula', 'fontFamily': 'Lato', 'fontSize': '14', 'lineNumber': true }, 'sortBy': 'UPDATED_AT', 'ui': { 'defaultNote': 'ALWAYS_ASK', 'disableDirectWrite': false, 'theme': 'default' }, 'zoom': 1 } + const allJson = { 'amaEnabled': true, 'editor': { 'fontFamily': 'Monaco, Consolas', 'fontSize': '14', 'indentSize': '2', 'indentType': 'space', 'keyMap': 'vim', 'switchPreview': 'BLUR', 'theme': 'monokai' }, 'hotkey': { 'toggleMain': 'Cmd + Alt + L' }, 'isSideNavFolded': false, 'listStyle': 'DEFAULT', 'listWidth': 174, 'navWidth': 200, 'preview': { 'codeBlockTheme': 'dracula', 'fontFamily': 'Lato', 'fontSize': '14', 'lineNumber': true }, 'sortBy': { 'default': 'UPDATED_AT' }, 'ui': { 'defaultNote': 'ALWAYS_ASK', 'disableDirectWrite': false, 'theme': 'default' }, 'zoom': 1 } // [input, expected] const validTestCases = [