Skip to content

Commit

Permalink
feat: add syncAdvancedMode to display different sync screens
Browse files Browse the repository at this point in the history
  • Loading branch information
pyphilia committed Apr 22, 2020
1 parent 9d7cb02 commit 934db99
Show file tree
Hide file tree
Showing 20 changed files with 1,198 additions and 604 deletions.
2 changes: 2 additions & 0 deletions public/app/config/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ module.exports = {
SIGN_IN_CHANNEL: 'auth:signin',
SIGN_OUT_CHANNEL: 'auth:signout',
IS_AUTHENTICATED_CHANNEL: 'auth:authenticated:get',
GET_SYNC_ADVANCED_MODE_CHANNEL: 'sync:advanced-mode:get',
SET_SYNC_ADVANCED_MODE_CHANNEL: 'sync:advanced-mode:set',
};
2 changes: 2 additions & 0 deletions public/app/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const TMP_FOLDER = 'tmp';
const DEFAULT_LANG = 'en';
const DEFAULT_DEVELOPER_MODE = false;
const DEFAULT_GEOLOCATION_ENABLED = false;
const DEFAULT_SYNC_ADVANCED_MODE = false;
const DEFAULT_PROTOCOL = 'https';
const DEFAULT_LOGGING_LEVEL = 'info';
const AUTHENTICATED = 'authenticated';
Expand Down Expand Up @@ -79,4 +80,5 @@ module.exports = {
DEFAULT_USER,
AUTHENTICATED,
ANONYMOUS_USERNAME,
DEFAULT_SYNC_ADVANCED_MODE,
};
6 changes: 6 additions & 0 deletions public/app/config/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ const CONNECTION_ONLINE_MESSAGE = 'You are online.';
const ERROR_SIGNING_IN = 'There was an error signing in.';
const ERROR_SIGNING_OUT = 'There was an error signing out.';
const ERROR_GETTING_AUTHENTICATED = 'There was an error during authentication.';
const ERROR_GETTING_SYNC_ADVANCED_MODE =
'There was an error getting the advanced mode in Space Synchronization';
const ERROR_SETTING_SYNC_ADVANCED_MODE =
'There was an error setting the advanced mode in Space Synchronization';

module.exports = {
ERROR_GETTING_DEVELOPER_MODE,
Expand Down Expand Up @@ -95,4 +99,6 @@ module.exports = {
ERROR_SIGNING_IN,
ERROR_SIGNING_OUT,
ERROR_GETTING_AUTHENTICATED,
ERROR_GETTING_SYNC_ADVANCED_MODE,
ERROR_SETTING_SYNC_ADVANCED_MODE,
};
18 changes: 18 additions & 0 deletions public/app/listeners/getSyncAdvancedMode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { DEFAULT_SYNC_ADVANCED_MODE } = require('../config/config');
const { GET_SYNC_ADVANCED_MODE_CHANNEL } = require('../config/channels');
const logger = require('../logger');
const { ERROR_GENERAL } = require('../config/errors');

const getSyncAdvancedMode = (mainWindow, db) => async () => {
try {
const advancedMode =
db.get('user.settings.syncAdvancedMode').value() ||
DEFAULT_SYNC_ADVANCED_MODE;
mainWindow.webContents.send(GET_SYNC_ADVANCED_MODE_CHANNEL, advancedMode);
} catch (e) {
logger.error(e);
mainWindow.webContents.send(GET_SYNC_ADVANCED_MODE_CHANNEL, ERROR_GENERAL);
}
};

module.exports = getSyncAdvancedMode;
4 changes: 4 additions & 0 deletions public/app/listeners/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const setLanguage = require('./setLanguage');
const getLanguage = require('./getLanguage');
const getDeveloperMode = require('./getDeveloperMode');
const setDeveloperMode = require('./setDeveloperMode');
const getSyncAdvancedMode = require('./getSyncAdvancedMode');
const setSyncAdvancedMode = require('./setSyncAdvancedMode');
const clearUserInput = require('./clearUserInput');
const showClearUserInputPrompt = require('./showClearUserInputPrompt');
const postAction = require('./postAction');
Expand Down Expand Up @@ -46,6 +48,8 @@ module.exports = {
getLanguage,
getDeveloperMode,
setDeveloperMode,
getSyncAdvancedMode,
setSyncAdvancedMode,
clearUserInput,
showClearUserInputPrompt,
postAction,
Expand Down
15 changes: 15 additions & 0 deletions public/app/listeners/setSyncAdvancedMode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { SET_SYNC_ADVANCED_MODE_CHANNEL } = require('../config/channels');
const { ERROR_GENERAL } = require('../config/errors');
const logger = require('../logger');

const setSyncAdvancedMode = (mainWindow, db) => async (event, advancedMode) => {
try {
db.set('user.settings.syncAdvancedMode', advancedMode).write();
mainWindow.webContents.send(SET_SYNC_ADVANCED_MODE_CHANNEL, advancedMode);
} catch (e) {
logger.error(e);
mainWindow.webContents.send(SET_SYNC_ADVANCED_MODE_CHANNEL, ERROR_GENERAL);
}
};

module.exports = setSyncAdvancedMode;
16 changes: 16 additions & 0 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const {
GET_APP_INSTANCE_CHANNEL,
GET_DEVELOPER_MODE_CHANNEL,
SET_DEVELOPER_MODE_CHANNEL,
GET_SYNC_ADVANCED_MODE_CHANNEL,
SET_SYNC_ADVANCED_MODE_CHANNEL,
GET_GEOLOCATION_ENABLED_CHANNEL,
SET_GEOLOCATION_ENABLED_CHANNEL,
GET_DATABASE_CHANNEL,
Expand Down Expand Up @@ -84,6 +86,8 @@ const {
postAppInstanceResource,
patchAppInstanceResource,
getAppInstance,
setSyncAdvancedMode,
getSyncAdvancedMode,
} = require('./app/listeners');
const isMac = require('./app/utils/isMac');

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

// called when setting sync advanced mode
ipcMain.on(
SET_SYNC_ADVANCED_MODE_CHANNEL,
setSyncAdvancedMode(mainWindow, db)
);

// called when getting sync advanced mode
ipcMain.on(
GET_SYNC_ADVANCED_MODE_CHANNEL,
getSyncAdvancedMode(mainWindow, db)
);

// called when getting geolocation enabled
ipcMain.on(
GET_GEOLOCATION_ENABLED_CHANNEL,
Expand Down
57 changes: 57 additions & 0 deletions src/actions/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ import {
SET_DEVELOPER_MODE_SUCCEEDED,
FLAG_GETTING_GEOLOCATION_ENABLED,
FLAG_SETTING_GEOLOCATION_ENABLED,
FLAG_GETTING_SYNC_ADVANCED_MODE,
FLAG_SETTING_SYNC_ADVANCED_MODE,
GET_GEOLOCATION_ENABLED_SUCCEEDED,
SET_GEOLOCATION_ENABLED_SUCCEEDED,
SET_SYNC_ADVANCED_MODE_SUCCEEDED,
GET_SYNC_ADVANCED_MODE_SUCCEEDED,
} from '../types';
import {
ERROR_GETTING_GEOLOCATION,
Expand All @@ -27,6 +31,8 @@ import {
ERROR_GETTING_DEVELOPER_MODE,
ERROR_SETTING_GEOLOCATION_ENABLED,
ERROR_GETTING_GEOLOCATION_ENABLED,
ERROR_GETTING_SYNC_ADVANCED_MODE,
ERROR_SETTING_SYNC_ADVANCED_MODE,
} from '../config/messages';
import {
GET_USER_FOLDER_CHANNEL,
Expand All @@ -36,6 +42,8 @@ import {
SET_DEVELOPER_MODE_CHANNEL,
GET_GEOLOCATION_ENABLED_CHANNEL,
SET_GEOLOCATION_ENABLED_CHANNEL,
GET_SYNC_ADVANCED_MODE_CHANNEL,
SET_SYNC_ADVANCED_MODE_CHANNEL,
} from '../config/channels';
import { createFlag } from './common';
import { ERROR_GENERAL } from '../config/errors';
Expand All @@ -51,6 +59,8 @@ const flagGettingGeolocationEnabled = createFlag(
const flagSettingGeolocationEnabled = createFlag(
FLAG_SETTING_GEOLOCATION_ENABLED
);
const flagGettingSyncAdvancedMode = createFlag(FLAG_GETTING_SYNC_ADVANCED_MODE);
const flagSettingSyncAdvancedMode = createFlag(FLAG_SETTING_SYNC_ADVANCED_MODE);

const getGeolocation = async () => async dispatch => {
// only fetch location if online
Expand Down Expand Up @@ -240,6 +250,51 @@ const setGeolocationEnabled = async geolocationEnabled => dispatch => {
}
};

const getSyncAdvancedMode = async () => dispatch => {
try {
dispatch(flagGettingSyncAdvancedMode(true));
window.ipcRenderer.send(GET_SYNC_ADVANCED_MODE_CHANNEL);
window.ipcRenderer.once(
GET_SYNC_ADVANCED_MODE_CHANNEL,
(event, syncAdvancedMode) => {
if (syncAdvancedMode === ERROR_GENERAL) {
toastr.error(ERROR_MESSAGE_HEADER, ERROR_GETTING_SYNC_ADVANCED_MODE);
} else {
dispatch({
type: GET_SYNC_ADVANCED_MODE_SUCCEEDED,
payload: syncAdvancedMode,
});
}
dispatch(flagGettingSyncAdvancedMode(false));
}
);
} catch (e) {
console.error(e);
toastr.error(ERROR_MESSAGE_HEADER, ERROR_GETTING_SYNC_ADVANCED_MODE);
}
};

const setSyncAdvancedMode = async syncAdvancedMode => dispatch => {
try {
dispatch(flagSettingSyncAdvancedMode(true));
window.ipcRenderer.send(SET_SYNC_ADVANCED_MODE_CHANNEL, syncAdvancedMode);
window.ipcRenderer.once(SET_SYNC_ADVANCED_MODE_CHANNEL, (event, mode) => {
if (mode === ERROR_GENERAL) {
toastr.error(ERROR_MESSAGE_HEADER, ERROR_SETTING_SYNC_ADVANCED_MODE);
} else {
dispatch({
type: SET_SYNC_ADVANCED_MODE_SUCCEEDED,
payload: mode,
});
}
dispatch(flagSettingSyncAdvancedMode(false));
});
} catch (e) {
console.error(e);
toastr.error(ERROR_MESSAGE_HEADER, ERROR_SETTING_SYNC_ADVANCED_MODE);
}
};

export {
getUserFolder,
getGeolocation,
Expand All @@ -249,4 +304,6 @@ export {
setDeveloperMode,
getGeolocationEnabled,
setGeolocationEnabled,
getSyncAdvancedMode,
setSyncAdvancedMode,
};
2 changes: 2 additions & 0 deletions src/components/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import DeveloperSwitch from './common/DeveloperSwitch';
import GeolocationControl from './common/GeolocationControl';
import Main from './common/Main';
import { SETTINGS_MAIN_ID } from '../config/selectors';
import SyncAdvancedSwitch from './space/sync/SyncAdvancedSwitch';

// eslint-disable-next-line react/prefer-stateless-function
export class Settings extends Component {
Expand Down Expand Up @@ -42,6 +43,7 @@ export class Settings extends Component {
<LanguageSelect />
<DeveloperSwitch />
<GeolocationControl />
<SyncAdvancedSwitch />
</FormGroup>
</div>
</Main>
Expand Down
1 change: 1 addition & 0 deletions src/components/__snapshots__/Settings.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ exports[`<Settings /> renders correctly 1`] = `
<withI18nextTranslation(WithStyles(Connect(LanguageSelect))) />
<withI18nextTranslation(WithStyles(Connect(DeveloperSwitch))) />
<withI18nextTranslation(WithStyles(Connect(GeolocationControl))) />
<withI18nextTranslation(WithStyles(Connect(SyncAdvancedSwitch))) />
</WithStyles(ForwardRef(FormGroup))>
</div>
</withI18nextTranslation(WithStyles(Connect(Main)))>
Expand Down
Loading

0 comments on commit 934db99

Please sign in to comment.