Skip to content

Commit 934db99

Browse files
committed
feat: add syncAdvancedMode to display different sync screens
1 parent 9d7cb02 commit 934db99

20 files changed

+1198
-604
lines changed

public/app/config/channels.js

+2
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,6 @@ module.exports = {
4545
SIGN_IN_CHANNEL: 'auth:signin',
4646
SIGN_OUT_CHANNEL: 'auth:signout',
4747
IS_AUTHENTICATED_CHANNEL: 'auth:authenticated:get',
48+
GET_SYNC_ADVANCED_MODE_CHANNEL: 'sync:advanced-mode:get',
49+
SET_SYNC_ADVANCED_MODE_CHANNEL: 'sync:advanced-mode:set',
4850
};

public/app/config/config.js

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const TMP_FOLDER = 'tmp';
4444
const DEFAULT_LANG = 'en';
4545
const DEFAULT_DEVELOPER_MODE = false;
4646
const DEFAULT_GEOLOCATION_ENABLED = false;
47+
const DEFAULT_SYNC_ADVANCED_MODE = false;
4748
const DEFAULT_PROTOCOL = 'https';
4849
const DEFAULT_LOGGING_LEVEL = 'info';
4950
const AUTHENTICATED = 'authenticated';
@@ -79,4 +80,5 @@ module.exports = {
7980
DEFAULT_USER,
8081
AUTHENTICATED,
8182
ANONYMOUS_USERNAME,
83+
DEFAULT_SYNC_ADVANCED_MODE,
8284
};

public/app/config/messages.js

+6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ const CONNECTION_ONLINE_MESSAGE = 'You are online.';
5353
const ERROR_SIGNING_IN = 'There was an error signing in.';
5454
const ERROR_SIGNING_OUT = 'There was an error signing out.';
5555
const ERROR_GETTING_AUTHENTICATED = 'There was an error during authentication.';
56+
const ERROR_GETTING_SYNC_ADVANCED_MODE =
57+
'There was an error getting the advanced mode in Space Synchronization';
58+
const ERROR_SETTING_SYNC_ADVANCED_MODE =
59+
'There was an error setting the advanced mode in Space Synchronization';
5660

5761
module.exports = {
5862
ERROR_GETTING_DEVELOPER_MODE,
@@ -95,4 +99,6 @@ module.exports = {
9599
ERROR_SIGNING_IN,
96100
ERROR_SIGNING_OUT,
97101
ERROR_GETTING_AUTHENTICATED,
102+
ERROR_GETTING_SYNC_ADVANCED_MODE,
103+
ERROR_SETTING_SYNC_ADVANCED_MODE,
98104
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const { DEFAULT_SYNC_ADVANCED_MODE } = require('../config/config');
2+
const { GET_SYNC_ADVANCED_MODE_CHANNEL } = require('../config/channels');
3+
const logger = require('../logger');
4+
const { ERROR_GENERAL } = require('../config/errors');
5+
6+
const getSyncAdvancedMode = (mainWindow, db) => async () => {
7+
try {
8+
const advancedMode =
9+
db.get('user.settings.syncAdvancedMode').value() ||
10+
DEFAULT_SYNC_ADVANCED_MODE;
11+
mainWindow.webContents.send(GET_SYNC_ADVANCED_MODE_CHANNEL, advancedMode);
12+
} catch (e) {
13+
logger.error(e);
14+
mainWindow.webContents.send(GET_SYNC_ADVANCED_MODE_CHANNEL, ERROR_GENERAL);
15+
}
16+
};
17+
18+
module.exports = getSyncAdvancedMode;

public/app/listeners/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const setLanguage = require('./setLanguage');
1616
const getLanguage = require('./getLanguage');
1717
const getDeveloperMode = require('./getDeveloperMode');
1818
const setDeveloperMode = require('./setDeveloperMode');
19+
const getSyncAdvancedMode = require('./getSyncAdvancedMode');
20+
const setSyncAdvancedMode = require('./setSyncAdvancedMode');
1921
const clearUserInput = require('./clearUserInput');
2022
const showClearUserInputPrompt = require('./showClearUserInputPrompt');
2123
const postAction = require('./postAction');
@@ -46,6 +48,8 @@ module.exports = {
4648
getLanguage,
4749
getDeveloperMode,
4850
setDeveloperMode,
51+
getSyncAdvancedMode,
52+
setSyncAdvancedMode,
4953
clearUserInput,
5054
showClearUserInputPrompt,
5155
postAction,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const { SET_SYNC_ADVANCED_MODE_CHANNEL } = require('../config/channels');
2+
const { ERROR_GENERAL } = require('../config/errors');
3+
const logger = require('../logger');
4+
5+
const setSyncAdvancedMode = (mainWindow, db) => async (event, advancedMode) => {
6+
try {
7+
db.set('user.settings.syncAdvancedMode', advancedMode).write();
8+
mainWindow.webContents.send(SET_SYNC_ADVANCED_MODE_CHANNEL, advancedMode);
9+
} catch (e) {
10+
logger.error(e);
11+
mainWindow.webContents.send(SET_SYNC_ADVANCED_MODE_CHANNEL, ERROR_GENERAL);
12+
}
13+
};
14+
15+
module.exports = setSyncAdvancedMode;

public/electron.js

+16
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ const {
4141
GET_APP_INSTANCE_CHANNEL,
4242
GET_DEVELOPER_MODE_CHANNEL,
4343
SET_DEVELOPER_MODE_CHANNEL,
44+
GET_SYNC_ADVANCED_MODE_CHANNEL,
45+
SET_SYNC_ADVANCED_MODE_CHANNEL,
4446
GET_GEOLOCATION_ENABLED_CHANNEL,
4547
SET_GEOLOCATION_ENABLED_CHANNEL,
4648
GET_DATABASE_CHANNEL,
@@ -84,6 +86,8 @@ const {
8486
postAppInstanceResource,
8587
patchAppInstanceResource,
8688
getAppInstance,
89+
setSyncAdvancedMode,
90+
getSyncAdvancedMode,
8791
} = require('./app/listeners');
8892
const isMac = require('./app/utils/isMac');
8993

@@ -392,6 +396,18 @@ app.on('ready', async () => {
392396
// called when setting developer mode
393397
ipcMain.on(SET_DEVELOPER_MODE_CHANNEL, setDeveloperMode(mainWindow, db));
394398

399+
// called when setting sync advanced mode
400+
ipcMain.on(
401+
SET_SYNC_ADVANCED_MODE_CHANNEL,
402+
setSyncAdvancedMode(mainWindow, db)
403+
);
404+
405+
// called when getting sync advanced mode
406+
ipcMain.on(
407+
GET_SYNC_ADVANCED_MODE_CHANNEL,
408+
getSyncAdvancedMode(mainWindow, db)
409+
);
410+
395411
// called when getting geolocation enabled
396412
ipcMain.on(
397413
GET_GEOLOCATION_ENABLED_CHANNEL,

src/actions/user.js

+57
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ import {
1414
SET_DEVELOPER_MODE_SUCCEEDED,
1515
FLAG_GETTING_GEOLOCATION_ENABLED,
1616
FLAG_SETTING_GEOLOCATION_ENABLED,
17+
FLAG_GETTING_SYNC_ADVANCED_MODE,
18+
FLAG_SETTING_SYNC_ADVANCED_MODE,
1719
GET_GEOLOCATION_ENABLED_SUCCEEDED,
1820
SET_GEOLOCATION_ENABLED_SUCCEEDED,
21+
SET_SYNC_ADVANCED_MODE_SUCCEEDED,
22+
GET_SYNC_ADVANCED_MODE_SUCCEEDED,
1923
} from '../types';
2024
import {
2125
ERROR_GETTING_GEOLOCATION,
@@ -27,6 +31,8 @@ import {
2731
ERROR_GETTING_DEVELOPER_MODE,
2832
ERROR_SETTING_GEOLOCATION_ENABLED,
2933
ERROR_GETTING_GEOLOCATION_ENABLED,
34+
ERROR_GETTING_SYNC_ADVANCED_MODE,
35+
ERROR_SETTING_SYNC_ADVANCED_MODE,
3036
} from '../config/messages';
3137
import {
3238
GET_USER_FOLDER_CHANNEL,
@@ -36,6 +42,8 @@ import {
3642
SET_DEVELOPER_MODE_CHANNEL,
3743
GET_GEOLOCATION_ENABLED_CHANNEL,
3844
SET_GEOLOCATION_ENABLED_CHANNEL,
45+
GET_SYNC_ADVANCED_MODE_CHANNEL,
46+
SET_SYNC_ADVANCED_MODE_CHANNEL,
3947
} from '../config/channels';
4048
import { createFlag } from './common';
4149
import { ERROR_GENERAL } from '../config/errors';
@@ -51,6 +59,8 @@ const flagGettingGeolocationEnabled = createFlag(
5159
const flagSettingGeolocationEnabled = createFlag(
5260
FLAG_SETTING_GEOLOCATION_ENABLED
5361
);
62+
const flagGettingSyncAdvancedMode = createFlag(FLAG_GETTING_SYNC_ADVANCED_MODE);
63+
const flagSettingSyncAdvancedMode = createFlag(FLAG_SETTING_SYNC_ADVANCED_MODE);
5464

5565
const getGeolocation = async () => async dispatch => {
5666
// only fetch location if online
@@ -240,6 +250,51 @@ const setGeolocationEnabled = async geolocationEnabled => dispatch => {
240250
}
241251
};
242252

253+
const getSyncAdvancedMode = async () => dispatch => {
254+
try {
255+
dispatch(flagGettingSyncAdvancedMode(true));
256+
window.ipcRenderer.send(GET_SYNC_ADVANCED_MODE_CHANNEL);
257+
window.ipcRenderer.once(
258+
GET_SYNC_ADVANCED_MODE_CHANNEL,
259+
(event, syncAdvancedMode) => {
260+
if (syncAdvancedMode === ERROR_GENERAL) {
261+
toastr.error(ERROR_MESSAGE_HEADER, ERROR_GETTING_SYNC_ADVANCED_MODE);
262+
} else {
263+
dispatch({
264+
type: GET_SYNC_ADVANCED_MODE_SUCCEEDED,
265+
payload: syncAdvancedMode,
266+
});
267+
}
268+
dispatch(flagGettingSyncAdvancedMode(false));
269+
}
270+
);
271+
} catch (e) {
272+
console.error(e);
273+
toastr.error(ERROR_MESSAGE_HEADER, ERROR_GETTING_SYNC_ADVANCED_MODE);
274+
}
275+
};
276+
277+
const setSyncAdvancedMode = async syncAdvancedMode => dispatch => {
278+
try {
279+
dispatch(flagSettingSyncAdvancedMode(true));
280+
window.ipcRenderer.send(SET_SYNC_ADVANCED_MODE_CHANNEL, syncAdvancedMode);
281+
window.ipcRenderer.once(SET_SYNC_ADVANCED_MODE_CHANNEL, (event, mode) => {
282+
if (mode === ERROR_GENERAL) {
283+
toastr.error(ERROR_MESSAGE_HEADER, ERROR_SETTING_SYNC_ADVANCED_MODE);
284+
} else {
285+
dispatch({
286+
type: SET_SYNC_ADVANCED_MODE_SUCCEEDED,
287+
payload: mode,
288+
});
289+
}
290+
dispatch(flagSettingSyncAdvancedMode(false));
291+
});
292+
} catch (e) {
293+
console.error(e);
294+
toastr.error(ERROR_MESSAGE_HEADER, ERROR_SETTING_SYNC_ADVANCED_MODE);
295+
}
296+
};
297+
243298
export {
244299
getUserFolder,
245300
getGeolocation,
@@ -249,4 +304,6 @@ export {
249304
setDeveloperMode,
250305
getGeolocationEnabled,
251306
setGeolocationEnabled,
307+
getSyncAdvancedMode,
308+
setSyncAdvancedMode,
252309
};

src/components/Settings.js

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import DeveloperSwitch from './common/DeveloperSwitch';
1111
import GeolocationControl from './common/GeolocationControl';
1212
import Main from './common/Main';
1313
import { SETTINGS_MAIN_ID } from '../config/selectors';
14+
import SyncAdvancedSwitch from './space/sync/SyncAdvancedSwitch';
1415

1516
// eslint-disable-next-line react/prefer-stateless-function
1617
export class Settings extends Component {
@@ -42,6 +43,7 @@ export class Settings extends Component {
4243
<LanguageSelect />
4344
<DeveloperSwitch />
4445
<GeolocationControl />
46+
<SyncAdvancedSwitch />
4547
</FormGroup>
4648
</div>
4749
</Main>

src/components/__snapshots__/Settings.test.js.snap

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ exports[`<Settings /> renders correctly 1`] = `
1717
<withI18nextTranslation(WithStyles(Connect(LanguageSelect))) />
1818
<withI18nextTranslation(WithStyles(Connect(DeveloperSwitch))) />
1919
<withI18nextTranslation(WithStyles(Connect(GeolocationControl))) />
20+
<withI18nextTranslation(WithStyles(Connect(SyncAdvancedSwitch))) />
2021
</WithStyles(ForwardRef(FormGroup))>
2122
</div>
2223
</withI18nextTranslation(WithStyles(Connect(Main)))>

0 commit comments

Comments
 (0)