Skip to content

Commit 978e984

Browse files
committed
feat: previsualize changes when sync space
1 parent 7f1461f commit 978e984

File tree

10 files changed

+485
-233
lines changed

10 files changed

+485
-233
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
"react-countup": "4.3.3",
110110
"react-detect-offline": "2.4.0",
111111
"react-dev-utils": "10.2.0",
112+
"react-diff-viewer": "3.0.2",
112113
"react-dom": "16.13.0",
113114
"react-i18next": "11.3.3",
114115
"react-immutable-proptypes": "2.1.0",

src/App.js

+7
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ import SpacesNearby from './components/SpacesNearby';
1515
import Settings from './components/Settings';
1616
import LoadSpace from './components/LoadSpace';
1717
import SpaceScreen from './components/space/SpaceScreen';
18+
import SyncScreen from './components/space/SyncScreen';
1819
import DeveloperScreen from './components/developer/DeveloperScreen';
1920
import { OnlineTheme, OfflineTheme } from './themes';
2021
import Dashboard from './components/dashboard/Dashboard';
2122
import SignInScreen from './components/signin/SignInScreen';
2223
import Authorization from './components/Authorization';
2324
import {
2425
SETTINGS_PATH,
26+
SYNC_SPACE_PATH,
2527
SPACE_PATH,
2628
HOME_PATH,
2729
SPACES_NEARBY_PATH,
@@ -179,6 +181,11 @@ export class App extends Component {
179181
path={SETTINGS_PATH}
180182
component={Authorization()(Settings)}
181183
/>
184+
<Route
185+
exact
186+
path={SYNC_SPACE_PATH}
187+
component={Authorization()(SyncScreen)}
188+
/>
182189
<Route
183190
exact
184191
path={SPACE_PATH}

src/actions/space.js

+16-27
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ import {
3939
SHOW_EXPORT_SPACE_PROMPT_CHANNEL,
4040
RESPOND_EXPORT_SPACE_PROMPT_CHANNEL,
4141
SAVE_SPACE_CHANNEL,
42-
SHOW_SYNC_SPACE_PROMPT_CHANNEL,
43-
RESPOND_SYNC_SPACE_PROMPT_CHANNEL,
4442
SYNC_SPACE_CHANNEL,
4543
SYNCED_SPACE_CHANNEL,
4644
CLEAR_USER_INPUT_CHANNEL,
@@ -147,25 +145,25 @@ const getRemoteSpace = async ({ id }) => async dispatch => {
147145
await isErrorResponse(response);
148146

149147
const remoteSpace = await response.json();
150-
let localSpace = {};
151-
152-
// try to merge with local space if available
153-
try {
154-
window.ipcRenderer.send(GET_SPACE_CHANNEL, { id });
155-
localSpace = await waitForSpace({ online: true });
156-
} catch (localError) {
157-
// ignore error
158-
}
148+
// let localSpace = {};
149+
150+
// // try to merge with local space if available
151+
// try {
152+
// window.ipcRenderer.send(GET_SPACE_CHANNEL, { id });
153+
// localSpace = await waitForSpace({ online: true });
154+
// } catch (localError) {
155+
// // ignore error
156+
// }
159157

160158
// in the future we could probably try to deep merge
161-
const space = {
162-
...remoteSpace,
163-
...localSpace,
164-
};
159+
// const space = {
160+
// ...remoteSpace,
161+
// ...localSpace,
162+
// };
165163

166164
dispatch({
167165
type: GET_SPACE_SUCCEEDED,
168-
payload: space,
166+
payload: remoteSpace,
169167
});
170168
} catch (err) {
171169
toastr.error(ERROR_MESSAGE_HEADER, ERROR_GETTING_SPACE_MESSAGE);
@@ -342,17 +340,8 @@ const syncSpace = async ({ id }) => async dispatch => {
342340
await isErrorResponse(response);
343341
const remoteSpace = await response.json();
344342

345-
// show confirmation prompt
346-
window.ipcRenderer.send(SHOW_SYNC_SPACE_PROMPT_CHANNEL);
347-
348-
// this runs when the user has responded to the sync dialog
349-
window.ipcRenderer.once(RESPOND_SYNC_SPACE_PROMPT_CHANNEL, (event, res) => {
350-
// only sync the space if the response is positive
351-
if (res === 1) {
352-
dispatch(flagSyncingSpace(true));
353-
window.ipcRenderer.send(SYNC_SPACE_CHANNEL, { remoteSpace });
354-
}
355-
});
343+
dispatch(flagSyncingSpace(true));
344+
window.ipcRenderer.send(SYNC_SPACE_CHANNEL, { remoteSpace });
356345

357346
// this runs once the space has been synced
358347
window.ipcRenderer.once(SYNCED_SPACE_CHANNEL, (event, res) => {

src/components/common/MainMenu.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class MainMenu extends Component {
4444
static propTypes = {
4545
t: PropTypes.func.isRequired,
4646
developerMode: PropTypes.bool.isRequired,
47-
history: PropTypes.shape({ replace: PropTypes.func.isRequired }).isRequired,
47+
history: PropTypes.shape({ push: PropTypes.func.isRequired }).isRequired,
4848
match: PropTypes.shape({ path: PropTypes.string.isRequired }).isRequired,
4949
dispatchSignOut: PropTypes.func.isRequired,
5050
authenticated: PropTypes.bool.isRequired,
@@ -54,13 +54,13 @@ export class MainMenu extends Component {
5454

5555
handleClick = path => {
5656
const {
57-
history: { replace },
57+
history: { push },
5858
} = this.props;
5959
if (path) {
60-
replace(path);
60+
push(path);
6161
} else {
6262
// default to home
63-
replace(HOME_PATH);
63+
push(HOME_PATH);
6464
}
6565
};
6666

src/components/common/__snapshots__/MediaCard.test.js.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ exports[`<MediaCard /> <MediaCard /> with showActions = true with text defined r
100100
}
101101
}
102102
/>
103-
<withI18nextTranslation(WithStyles(Connect(SyncButton)))
103+
<withRouter(withI18nextTranslation(WithStyles(SyncButton)))
104104
spaceId="id"
105105
/>
106106
<WithStyles(ForwardRef(IconButton))
@@ -172,7 +172,7 @@ exports[`<MediaCard /> <MediaCard /> with showActions = true with text undefined
172172
}
173173
}
174174
/>
175-
<withI18nextTranslation(WithStyles(Connect(SyncButton)))
175+
<withRouter(withI18nextTranslation(WithStyles(SyncButton)))
176176
spaceId="id"
177177
/>
178178
</WithStyles(ForwardRef(CardActions))>

src/components/space/SpaceGrid.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class SpaceGrid extends Component {
3030
).isRequired,
3131
history: PropTypes.shape({
3232
length: PropTypes.number.isRequired,
33-
replace: PropTypes.func.isRequired,
33+
push: PropTypes.func.isRequired,
3434
}).isRequired,
3535
dispatchClearSpace: PropTypes.func.isRequired,
3636
t: PropTypes.func.isRequired,
@@ -124,10 +124,10 @@ class SpaceGrid extends Component {
124124

125125
[...spaces].forEach((space, index) => {
126126
const { id, image = {}, description } = space;
127-
const { replace } = history;
127+
const { push } = history;
128128

129129
const viewLink = () => {
130-
replace(`/space/${id}?saved=${saved}`);
130+
push(`/space/${id}?saved=${saved}`);
131131
};
132132

133133
const card = (

src/components/space/SyncButton.js

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
3-
import { connect } from 'react-redux';
43
import clsx from 'clsx';
4+
import { withRouter } from 'react-router';
55
import { withTranslation } from 'react-i18next';
66
import IconButton from '@material-ui/core/IconButton/IconButton';
77
import SyncIcon from '@material-ui/icons/Sync';
88
import { Online, Offline } from 'react-detect-offline';
99
import Tooltip from '@material-ui/core/Tooltip';
1010
import { withStyles } from '@material-ui/core';
1111
import Styles from '../../Styles';
12-
import { syncSpace } from '../../actions/space';
1312
import { SPACE_SYNC_BUTTON_CLASS } from '../../config/selectors';
1413

1514
class SyncButton extends Component {
@@ -19,13 +18,18 @@ class SyncButton extends Component {
1918
appBar: PropTypes.string.isRequired,
2019
button: PropTypes.string.isRequired,
2120
}).isRequired,
22-
dispatchSyncSpace: PropTypes.func.isRequired,
2321
t: PropTypes.func.isRequired,
22+
history: PropTypes.shape({
23+
push: PropTypes.func.isRequired,
24+
}).isRequired,
2425
};
2526

2627
handleSync = () => {
27-
const { spaceId: id, dispatchSyncSpace } = this.props;
28-
dispatchSyncSpace({ id });
28+
const {
29+
spaceId,
30+
history: { push },
31+
} = this.props;
32+
return push(`/space/sync/${spaceId}?saved=true`);
2933
};
3034

3135
render() {
@@ -60,16 +64,9 @@ class SyncButton extends Component {
6064
);
6165
}
6266
}
63-
const mapDispatchToProps = {
64-
dispatchSyncSpace: syncSpace,
65-
};
66-
67-
const ConnectedComponent = connect(null, mapDispatchToProps)(SyncButton);
6867

69-
const StyledComponent = withStyles(Styles, { withTheme: true })(
70-
ConnectedComponent
71-
);
68+
const StyledComponent = withStyles(Styles, { withTheme: true })(SyncButton);
7269

7370
const TranslatedComponent = withTranslation()(StyledComponent);
7471

75-
export default TranslatedComponent;
72+
export default withRouter(TranslatedComponent);

0 commit comments

Comments
 (0)