diff --git a/ElectronClient/app/app.js b/ElectronClient/app/app.js index 3a5853dd9..1c7ca88cd 100644 --- a/ElectronClient/app/app.js +++ b/ElectronClient/app/app.js @@ -29,6 +29,7 @@ const appDefaultState = Object.assign({}, defaultState, { navHistory: [], fileToImport: null, windowCommand: null, + noteVisiblePanes: ['editor', 'viewer'], }); class Application extends BaseApplication { @@ -91,6 +92,29 @@ class Application extends BaseApplication { newState.windowCommand = command; break; + case 'NOTE_VISIBLE_PANES_TOGGLE': + + let panes = state.noteVisiblePanes.slice(); + if (panes.length === 2) { + panes = ['editor']; + } else if (panes.indexOf('editor') >= 0) { + panes = ['viewer']; + } else if (panes.indexOf('viewer') >= 0) { + panes = ['editor', 'viewer']; + } else { + panes = ['editor', 'viewer']; + } + + newState = Object.assign({}, state); + newState.noteVisiblePanes = panes; + break; + + case 'NOTE_VISIBLE_PANES_SET': + + newState = Object.assign({}, state); + newState.noteVisiblePanes = action.panes; + break; + } } catch (error) { error.message = 'In reducer: ' + error.message + ' Action: ' + JSON.stringify(action); @@ -108,7 +132,7 @@ class Application extends BaseApplication { if (['NOTE_UPDATE_ONE', 'NOTE_DELETE', 'FOLDER_UPDATE_ONE', 'FOLDER_DELETE'].indexOf(action.type) >= 0) { if (!await reg.syncStarted()) reg.scheduleSync(); - } + } const result = await super.generalMiddleware(store, next, action); const newState = store.getState(); @@ -117,6 +141,10 @@ class Application extends BaseApplication { app().updateMenu(newState.route.routeName); } + if (['NOTE_VISIBLE_PANES_TOGGLE', 'NOTE_VISIBLE_PANES_SET'].indexOf(action.type) >= 0) { + Setting.setValue('noteVisiblePanes', newState.noteVisiblePanes); + } + return result; } diff --git a/ElectronClient/app/gui/MainScreen.jsx b/ElectronClient/app/gui/MainScreen.jsx index 77d7b5be5..2dcc718ee 100644 --- a/ElectronClient/app/gui/MainScreen.jsx +++ b/ElectronClient/app/gui/MainScreen.jsx @@ -19,7 +19,6 @@ class MainScreenComponent extends React.Component { componentWillMount() { this.setState({ promptOptions: null, - noteVisiblePanes: ['editor', 'viewer'], }); } @@ -30,16 +29,9 @@ class MainScreenComponent extends React.Component { } toggleVisiblePanes() { - let panes = this.state.noteVisiblePanes.slice(); - if (panes.length === 2) { - panes = ['editor']; - } else if (panes.indexOf('editor') >= 0) { - panes = ['viewer']; - } else if (panes.indexOf('viewer') >= 0) { - panes = ['editor', 'viewer']; - } - - this.setState({ noteVisiblePanes: panes }); + this.props.dispatch({ + type: 'NOTE_VISIBLE_PANES_TOGGLE', + }); } async doCommand(command) { @@ -216,7 +208,7 @@ class MainScreenComponent extends React.Component {
- + ); } @@ -227,6 +219,7 @@ const mapStateToProps = (state) => { return { theme: state.settings.theme, windowCommand: state.windowCommand, + noteVisiblePanes: state.noteVisiblePanes, }; }; diff --git a/ElectronClient/app/gui/Root.jsx b/ElectronClient/app/gui/Root.jsx index d432ff4a5..87a4fef90 100644 --- a/ElectronClient/app/gui/Root.jsx +++ b/ElectronClient/app/gui/Root.jsx @@ -34,6 +34,11 @@ async function initialize(dispatch) { type: 'WINDOW_CONTENT_SIZE_SET', size: bridge().windowContentSize(), }); + + store.dispatch({ + type: 'NOTE_VISIBLE_PANES_SET', + panes: Setting.value('noteVisiblePanes'), + }); } class RootComponent extends React.Component { diff --git a/ReactNativeClient/lib/models/setting.js b/ReactNativeClient/lib/models/setting.js index 1534737cd..968156809 100644 --- a/ReactNativeClient/lib/models/setting.js +++ b/ReactNativeClient/lib/models/setting.js @@ -142,12 +142,15 @@ class Setting extends BaseModel { value = this.formatValue(key, value); if (md.type == Setting.TYPE_INT) return value.toFixed(0); if (md.type == Setting.TYPE_BOOL) return value ? '1' : '0'; + if (md.type == Setting.TYPE_ARRAY) return value ? JSON.stringify(value) : '[]'; return value; } static formatValue(key, value) { const md = this.settingMetadata(key); + if (md.type == Setting.TYPE_INT) return Math.floor(Number(value)); + if (md.type == Setting.TYPE_BOOL) { if (typeof value === 'string') { value = value.toLowerCase(); @@ -157,6 +160,13 @@ class Setting extends BaseModel { } return !!value; } + + if (md.type === Setting.TYPE_ARRAY) { + if (Array.isArray(value)) return value; + if (typeof value === 'string') return JSON.parse(value); + return []; + } + return value; } @@ -297,6 +307,7 @@ class Setting extends BaseModel { if (typeId === Setting.TYPE_INT) return 'int'; if (typeId === Setting.TYPE_STRING) return 'string'; if (typeId === Setting.TYPE_BOOL) return 'bool'; + if (typeId === Setting.TYPE_ARRAY) return 'array'; } } @@ -308,6 +319,7 @@ Setting.SYNC_TARGET_ONEDRIVE = 3; Setting.TYPE_INT = 1; Setting.TYPE_STRING = 2; Setting.TYPE_BOOL = 3; +Setting.TYPE_ARRAY = 4; Setting.THEME_LIGHT = 1; Setting.THEME_DARK = 2; @@ -363,6 +375,7 @@ Setting.metadata_ = { }; }}, 'showAdvancedOptions': { value: false, type: Setting.TYPE_BOOL, public: true, appTypes: ['mobile', 'desktop'], label: () => _('Show advanced options') }, + 'noteVisiblePanes': { value: ['editor', 'viewer'], type: Setting.TYPE_ARRAY, public: false, appTypes: ['desktop'] }, }; // Contains constants that are set by the application and