Skip to content

Commit 2823cf2

Browse files
committed
fix: visit a space just after delete
1 parent 85a75a7 commit 2823cf2

13 files changed

+131
-99
lines changed

public/app/listeners/getAppUpgrade.js

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ const {
77
const { ERROR_GENERAL } = require('../config/errors');
88

99
const getAppUpgrade = (mainWindow) => async () => {
10+
// disable app upgrade on test
11+
if (process.env.NODE_ENV === 'test') {
12+
mainWindow.webContents.send(GET_APP_UPGRADE_CHANNEL, false);
13+
}
14+
1015
// app update
1116
autoUpdater.logger = logger;
1217
autoUpdater.autoDownload = false;

src/actions/space.js

+17-16
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const createGetLocalSpace = async (
9797
type,
9898
flagType,
9999
showError = true
100-
) => async dispatch => {
100+
) => async (dispatch) => {
101101
const flagGettingSpace = createFlag(flagType);
102102
try {
103103
dispatch(flagGettingSpace(true));
@@ -123,14 +123,12 @@ const createGetLocalSpace = async (
123123
}
124124
};
125125

126-
const getLocalSpace = payload =>
126+
const getLocalSpace = (payload) =>
127127
createGetLocalSpace(payload, GET_SPACE_SUCCEEDED, FLAG_GETTING_SPACE);
128128

129-
const createGetRemoteSpace = async (
130-
{ id },
131-
type,
132-
flagType
133-
) => async dispatch => {
129+
const createGetRemoteSpace = async ({ id }, type, flagType) => async (
130+
dispatch
131+
) => {
134132
const flagGettingSpace = createFlag(flagType);
135133
try {
136134
dispatch(flagGettingSpace(true));
@@ -174,10 +172,10 @@ const createGetRemoteSpace = async (
174172
}
175173
};
176174

177-
const getRemoteSpace = payload =>
175+
const getRemoteSpace = (payload) =>
178176
createGetRemoteSpace(payload, GET_SPACE_SUCCEEDED, FLAG_GETTING_SPACE);
179177

180-
const getSpaces = () => dispatch => {
178+
const getSpaces = () => (dispatch) => {
181179
dispatch(flagGettingSpaces(true));
182180
window.ipcRenderer.send(GET_SPACES_CHANNEL);
183181
// create listener
@@ -191,7 +189,7 @@ const getSpaces = () => dispatch => {
191189
});
192190
};
193191

194-
const saveSpace = async ({ space }) => async dispatch => {
192+
const saveSpace = async ({ space }) => async (dispatch) => {
195193
try {
196194
dispatch(flagSavingSpace(true));
197195

@@ -246,14 +244,14 @@ const saveSpace = async ({ space }) => async dispatch => {
246244
}
247245
};
248246

249-
const clearSpace = () => dispatch => {
247+
const clearSpace = () => (dispatch) => {
250248
dispatch(clearPhase());
251249
return dispatch({
252250
type: CLEAR_SPACE,
253251
});
254252
};
255253

256-
const deleteSpace = ({ id }) => dispatch => {
254+
const deleteSpace = ({ id }, onSuccess) => (dispatch) => {
257255
// show confirmation prompt
258256
const buttons = [i18n.t('Cancel'), i18n.t('Delete')];
259257
window.ipcRenderer.send(SHOW_DELETE_SPACE_PROMPT_CHANNEL, {
@@ -276,6 +274,9 @@ const deleteSpace = ({ id }) => dispatch => {
276274
i18n.t(ERROR_DELETING_MESSAGE)
277275
);
278276
} else {
277+
// eslint-disable-next-line no-unused-expressions
278+
onSuccess?.();
279+
279280
// update saved spaces in state
280281
dispatch(getSpaces());
281282

@@ -299,7 +300,7 @@ const deleteSpace = ({ id }) => dispatch => {
299300
});
300301
};
301302

302-
const clearUserInput = async ({ spaceId, userId }) => async dispatch => {
303+
const clearUserInput = async ({ spaceId, userId }) => async (dispatch) => {
303304
try {
304305
// show confirmation prompt
305306
const buttons = [i18n.t('Cancel'), i18n.t('Clear')];
@@ -346,7 +347,7 @@ const clearUserInput = async ({ spaceId, userId }) => async dispatch => {
346347
}
347348
};
348349

349-
const getSpace = ({ id, saved = false, user }) => dispatch => {
350+
const getSpace = ({ id, saved = false, user }) => (dispatch) => {
350351
// only get the space from the api if not saved
351352
if (!saved) {
352353
dispatch(getRemoteSpace({ id }));
@@ -359,7 +360,7 @@ const getSpacesNearby = async ({
359360
latitude,
360361
longitude,
361362
radius = DEFAULT_RADIUS,
362-
}) => async dispatch => {
363+
}) => async (dispatch) => {
363364
try {
364365
dispatch(flagGettingSpacesNearby(true));
365366

@@ -385,7 +386,7 @@ const getSpacesNearby = async ({
385386
}
386387
};
387388

388-
const setSearchQuery = async payload => async dispatch => {
389+
const setSearchQuery = async (payload) => async (dispatch) => {
389390
dispatch({
390391
type: SET_SPACE_SEARCH_QUERY_SUCCEEDED,
391392
payload,

src/components/VisitSpace.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ class VisitSpace extends Component {
5757
}).isRequired,
5858
activity: PropTypes.bool,
5959
history: PropTypes.shape({
60-
replace: PropTypes.func.isRequired,
60+
push: PropTypes.func.isRequired,
6161
}).isRequired,
6262
};
6363

6464
static defaultProps = {
6565
activity: false,
6666
};
6767

68-
handleChangeSpaceId = event => {
68+
handleChangeSpaceId = (event) => {
6969
const spaceId = event.target.value;
7070
this.setState({ spaceId });
7171
};
@@ -81,13 +81,13 @@ class VisitSpace extends Component {
8181
return toastr.error(t(ERROR_MESSAGE_HEADER), t(INVALID_SPACE_ID_OR_URL));
8282
}
8383
if (id && id !== '') {
84-
const { replace } = history;
85-
return replace(`/space/${id}`);
84+
const { push } = history;
85+
return push(`/space/${id}`);
8686
}
8787
return false;
8888
};
8989

90-
handleKeyPress = event => {
90+
handleKeyPress = (event) => {
9191
if (event.key === 'Enter') {
9292
this.handleClick();
9393
}

src/components/space/DeleteButton.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@ class DeleteButton extends Component {
2020
}).isRequired,
2121
dispatchDeleteSpace: PropTypes.func.isRequired,
2222
t: PropTypes.func.isRequired,
23+
onSuccess: PropTypes.func,
24+
};
25+
26+
static defaultProps = {
27+
onSuccess: null,
2328
};
2429

2530
handleDelete = () => {
26-
const { spaceId: id, dispatchDeleteSpace } = this.props;
27-
dispatchDeleteSpace({ id });
31+
const { spaceId: id, dispatchDeleteSpace, onSuccess } = this.props;
32+
dispatchDeleteSpace({ id }, onSuccess);
2833
};
2934

3035
render() {

src/components/space/SpaceGrid.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class SpaceGrid extends Component {
149149

150150
const MediaCards = [];
151151

152-
columnWrapper.items.forEach(column => {
152+
columnWrapper.items.forEach((column) => {
153153
MediaCards.push(
154154
<div
155155
style={{
@@ -173,9 +173,8 @@ class SpaceGrid extends Component {
173173
}
174174
}
175175

176-
const mapStateToProps = ({ authentication, Space }) => ({
176+
const mapStateToProps = ({ authentication }) => ({
177177
folder: authentication.getIn(['current', 'folder']),
178-
deleted: Space.getIn(['current', 'deleted']),
179178
});
180179

181180
const mapDispatchToProps = {

src/components/space/SpaceHeader.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { Component } from 'react';
22
import classNames from 'classnames';
33
import PropTypes from 'prop-types';
44
import { connect } from 'react-redux';
5+
import { withRouter } from 'react-router';
56
import clsx from 'clsx';
67
import MenuIcon from '@material-ui/icons/Menu';
78
import AppBar from '@material-ui/core/AppBar/AppBar';
@@ -48,6 +49,9 @@ class SpaceHeader extends Component {
4849
dispatchSaveSpace: PropTypes.func.isRequired,
4950
t: PropTypes.func.isRequired,
5051
userMode: PropTypes.oneOf(Object.values(USER_MODES)).isRequired,
52+
history: PropTypes.shape({
53+
goBack: PropTypes.func.isRequired,
54+
}).isRequired,
5155
};
5256

5357
handleSave = () => {
@@ -93,10 +97,16 @@ class SpaceHeader extends Component {
9397
}
9498

9599
renderDeleteButton() {
96-
const { space } = this.props;
100+
const {
101+
space,
102+
history: { goBack },
103+
} = this.props;
97104
const { saved, id } = space;
98105
if (saved) {
99-
return <DeleteButton spaceId={id} />;
106+
const onSuccess = () => {
107+
goBack();
108+
};
109+
return <DeleteButton spaceId={id} onSuccess={onSuccess} />;
100110
}
101111
return null;
102112
}
@@ -203,9 +213,7 @@ class SpaceHeader extends Component {
203213
}
204214

205215
const mapStateToProps = ({ Space, authentication }) => ({
206-
space: Space.get('current')
207-
.get('content')
208-
.toJS(),
216+
space: Space.get('current').get('content').toJS(),
209217
userMode: authentication.getIn(['user', 'settings', 'userMode']),
210218
});
211219

@@ -224,4 +232,4 @@ const StyledComponent = withStyles(Styles, { withTheme: true })(
224232

225233
const TranslatedComponent = withTranslation()(StyledComponent);
226234

227-
export default TranslatedComponent;
235+
export default withRouter(TranslatedComponent);

src/components/space/SpaceScreen.js

+5-20
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
} from '../../actions';
3030
import './SpaceScreen.css';
3131
import Styles from '../../Styles';
32-
import { HOME_PATH } from '../../config/paths';
3332
import SpaceHeader from './SpaceHeader';
3433
import SpaceNotFound from './SpaceNotFound';
3534
import MainMenu from '../common/MainMenu';
@@ -60,7 +59,6 @@ class SpaceScreen extends Component {
6059
dispatchGetSpace: PropTypes.func.isRequired,
6160
dispatchClearSpace: PropTypes.func.isRequired,
6261
activity: PropTypes.bool.isRequired,
63-
deleted: PropTypes.bool.isRequired,
6462
classes: PropTypes.shape({
6563
root: PropTypes.string.isRequired,
6664
appBar: PropTypes.string.isRequired,
@@ -82,7 +80,7 @@ class SpaceScreen extends Component {
8280
}).isRequired,
8381
history: PropTypes.shape({
8482
length: PropTypes.number.isRequired,
85-
replace: PropTypes.func.isRequired,
83+
goBack: PropTypes.func.isRequired,
8684
}).isRequired,
8785
recentSpaces: PropTypes.instanceOf(ImmList).isRequired,
8886
dispatchSetSpaceAsRecent: PropTypes.func.isRequired,
@@ -104,18 +102,8 @@ class SpaceScreen extends Component {
104102

105103
componentDidUpdate() {
106104
const { selected } = this.state;
107-
const {
108-
deleted,
109-
phase,
110-
history: { replace },
111-
space,
112-
recentSpaces,
113-
dispatchSetSpaceAsRecent,
114-
} = this.props;
115-
// redirect to home if space is deleted
116-
if (deleted) {
117-
replace(HOME_PATH);
118-
} else if (selected !== -1 && (!phase || phase.isEmpty())) {
105+
const { phase, space, recentSpaces, dispatchSetSpaceAsRecent } = this.props;
106+
if (selected !== -1 && (!phase || phase.isEmpty())) {
119107
// eslint-disable-next-line react/no-did-update-set-state
120108
this.setState({ selected: -1 });
121109
}
@@ -145,7 +133,7 @@ class SpaceScreen extends Component {
145133
this.setState({ openDrawer: false });
146134
};
147135

148-
handlePhaseClicked = i => {
136+
handlePhaseClicked = (i) => {
149137
const { dispatchSelectPhase, space } = this.props;
150138
const phases = space.get('phases');
151139
dispatchSelectPhase(phases[i]);
@@ -251,12 +239,9 @@ class SpaceScreen extends Component {
251239

252240
const mapStateToProps = ({ Space, Phase, authentication }) => ({
253241
space: Space.get('current').get('content'),
254-
open: Space.get('current')
255-
.get('menu')
256-
.get('open'),
242+
open: Space.get('current').get('menu').get('open'),
257243
phase: Phase.get('current').get('content'),
258244
activity: Boolean(Space.getIn(['current', 'activity']).size),
259-
deleted: Space.get('current').get('deleted'),
260245
recentSpaces: authentication.getIn(['user', 'recentSpaces']),
261246
});
262247

src/components/space/SyncAdvancedScreen.js

-12
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import Loader from '../common/Loader';
1616
import { clearSpacesForSync } from '../../actions';
1717
import './SpaceScreen.css';
1818
import Styles from '../../Styles';
19-
import { HOME_PATH } from '../../config/paths';
2019
import SpaceNotFound from './SpaceNotFound';
2120
import { SYNC_SPACE_PROPERTIES } from '../../config/constants';
2221
import SyncCancelButton from './sync/SyncCancelButton';
@@ -77,17 +76,6 @@ class SyncAdvancedScreen extends Component {
7776
t: PropTypes.func.isRequired,
7877
};
7978

80-
componentDidUpdate() {
81-
const {
82-
localSpace: { deleted },
83-
history: { replace },
84-
} = this.props;
85-
// redirect to home if space is deleted
86-
if (deleted) {
87-
replace(HOME_PATH);
88-
}
89-
}
90-
9179
componentWillUnmount() {
9280
const { dispatchClearSpaces } = this.props;
9381
dispatchClearSpaces();

src/components/space/SyncScreen.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import Styles from '../../Styles';
2727
import Loader from '../common/Loader';
2828
import { DEFAULT_SYNC_MODE, SYNC_MODES } from '../../config/constants';
2929

30-
const styles = theme => ({
30+
const styles = (theme) => ({
3131
...Styles(theme),
3232
centerText: {
3333
textAlign: 'center',
@@ -53,7 +53,6 @@ class SyncScreen extends Component {
5353
id: PropTypes.string,
5454
description: PropTypes.string,
5555
name: PropTypes.string,
56-
deleted: PropTypes.bool,
5756
}),
5857
remoteSpace: ImmutablePropTypes.contains({
5958
id: PropTypes.string,

0 commit comments

Comments
 (0)