Skip to content

Commit

Permalink
Merge pull request #353 from graasp/352/visitDelete
Browse files Browse the repository at this point in the history
fix: visit a space just after delete
  • Loading branch information
pyphilia committed Nov 17, 2020
2 parents 85a75a7 + dde059e commit 6301fed
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 104 deletions.
5 changes: 5 additions & 0 deletions public/app/listeners/getAppUpgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ const {
const { ERROR_GENERAL } = require('../config/errors');

const getAppUpgrade = (mainWindow) => async () => {
// disable app upgrade on test
if (process.env.NODE_ENV === 'test') {
mainWindow.webContents.send(GET_APP_UPGRADE_CHANNEL, false);
}

// app update
autoUpdater.logger = logger;
autoUpdater.autoDownload = false;
Expand Down
33 changes: 17 additions & 16 deletions src/actions/space.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const createGetLocalSpace = async (
type,
flagType,
showError = true
) => async dispatch => {
) => async (dispatch) => {
const flagGettingSpace = createFlag(flagType);
try {
dispatch(flagGettingSpace(true));
Expand All @@ -123,14 +123,12 @@ const createGetLocalSpace = async (
}
};

const getLocalSpace = payload =>
const getLocalSpace = (payload) =>
createGetLocalSpace(payload, GET_SPACE_SUCCEEDED, FLAG_GETTING_SPACE);

const createGetRemoteSpace = async (
{ id },
type,
flagType
) => async dispatch => {
const createGetRemoteSpace = async ({ id }, type, flagType) => async (
dispatch
) => {
const flagGettingSpace = createFlag(flagType);
try {
dispatch(flagGettingSpace(true));
Expand Down Expand Up @@ -174,10 +172,10 @@ const createGetRemoteSpace = async (
}
};

const getRemoteSpace = payload =>
const getRemoteSpace = (payload) =>
createGetRemoteSpace(payload, GET_SPACE_SUCCEEDED, FLAG_GETTING_SPACE);

const getSpaces = () => dispatch => {
const getSpaces = () => (dispatch) => {
dispatch(flagGettingSpaces(true));
window.ipcRenderer.send(GET_SPACES_CHANNEL);
// create listener
Expand All @@ -191,7 +189,7 @@ const getSpaces = () => dispatch => {
});
};

const saveSpace = async ({ space }) => async dispatch => {
const saveSpace = async ({ space }) => async (dispatch) => {
try {
dispatch(flagSavingSpace(true));

Expand Down Expand Up @@ -246,14 +244,14 @@ const saveSpace = async ({ space }) => async dispatch => {
}
};

const clearSpace = () => dispatch => {
const clearSpace = () => (dispatch) => {
dispatch(clearPhase());
return dispatch({
type: CLEAR_SPACE,
});
};

const deleteSpace = ({ id }) => dispatch => {
const deleteSpace = ({ id }, onSuccess) => (dispatch) => {
// show confirmation prompt
const buttons = [i18n.t('Cancel'), i18n.t('Delete')];
window.ipcRenderer.send(SHOW_DELETE_SPACE_PROMPT_CHANNEL, {
Expand All @@ -276,6 +274,9 @@ const deleteSpace = ({ id }) => dispatch => {
i18n.t(ERROR_DELETING_MESSAGE)
);
} else {
// eslint-disable-next-line no-unused-expressions
onSuccess?.();

// update saved spaces in state
dispatch(getSpaces());

Expand All @@ -299,7 +300,7 @@ const deleteSpace = ({ id }) => dispatch => {
});
};

const clearUserInput = async ({ spaceId, userId }) => async dispatch => {
const clearUserInput = async ({ spaceId, userId }) => async (dispatch) => {
try {
// show confirmation prompt
const buttons = [i18n.t('Cancel'), i18n.t('Clear')];
Expand Down Expand Up @@ -346,7 +347,7 @@ const clearUserInput = async ({ spaceId, userId }) => async dispatch => {
}
};

const getSpace = ({ id, saved = false, user }) => dispatch => {
const getSpace = ({ id, saved = false, user }) => (dispatch) => {
// only get the space from the api if not saved
if (!saved) {
dispatch(getRemoteSpace({ id }));
Expand All @@ -359,7 +360,7 @@ const getSpacesNearby = async ({
latitude,
longitude,
radius = DEFAULT_RADIUS,
}) => async dispatch => {
}) => async (dispatch) => {
try {
dispatch(flagGettingSpacesNearby(true));

Expand All @@ -385,7 +386,7 @@ const getSpacesNearby = async ({
}
};

const setSearchQuery = async payload => async dispatch => {
const setSearchQuery = async (payload) => async (dispatch) => {
dispatch({
type: SET_SPACE_SEARCH_QUERY_SUCCEEDED,
payload,
Expand Down
10 changes: 5 additions & 5 deletions src/components/VisitSpace.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ class VisitSpace extends Component {
}).isRequired,
activity: PropTypes.bool,
history: PropTypes.shape({
replace: PropTypes.func.isRequired,
push: PropTypes.func.isRequired,
}).isRequired,
};

static defaultProps = {
activity: false,
};

handleChangeSpaceId = event => {
handleChangeSpaceId = (event) => {
const spaceId = event.target.value;
this.setState({ spaceId });
};
Expand All @@ -81,13 +81,13 @@ class VisitSpace extends Component {
return toastr.error(t(ERROR_MESSAGE_HEADER), t(INVALID_SPACE_ID_OR_URL));
}
if (id && id !== '') {
const { replace } = history;
return replace(`/space/${id}`);
const { push } = history;
return push(`/space/${id}`);
}
return false;
};

handleKeyPress = event => {
handleKeyPress = (event) => {
if (event.key === 'Enter') {
this.handleClick();
}
Expand Down
9 changes: 7 additions & 2 deletions src/components/space/DeleteButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ class DeleteButton extends Component {
}).isRequired,
dispatchDeleteSpace: PropTypes.func.isRequired,
t: PropTypes.func.isRequired,
onSuccess: PropTypes.func,
};

static defaultProps = {
onSuccess: null,
};

handleDelete = () => {
const { spaceId: id, dispatchDeleteSpace } = this.props;
dispatchDeleteSpace({ id });
const { spaceId: id, dispatchDeleteSpace, onSuccess } = this.props;
dispatchDeleteSpace({ id }, onSuccess);
};

render() {
Expand Down
5 changes: 2 additions & 3 deletions src/components/space/SpaceGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class SpaceGrid extends Component {

const MediaCards = [];

columnWrapper.items.forEach(column => {
columnWrapper.items.forEach((column) => {
MediaCards.push(
<div
style={{
Expand All @@ -173,9 +173,8 @@ class SpaceGrid extends Component {
}
}

const mapStateToProps = ({ authentication, Space }) => ({
const mapStateToProps = ({ authentication }) => ({
folder: authentication.getIn(['current', 'folder']),
deleted: Space.getIn(['current', 'deleted']),
});

const mapDispatchToProps = {
Expand Down
20 changes: 14 additions & 6 deletions src/components/space/SpaceHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component } from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { withRouter } from 'react-router';
import clsx from 'clsx';
import MenuIcon from '@material-ui/icons/Menu';
import AppBar from '@material-ui/core/AppBar/AppBar';
Expand Down Expand Up @@ -48,6 +49,9 @@ class SpaceHeader extends Component {
dispatchSaveSpace: PropTypes.func.isRequired,
t: PropTypes.func.isRequired,
userMode: PropTypes.oneOf(Object.values(USER_MODES)).isRequired,
history: PropTypes.shape({
goBack: PropTypes.func.isRequired,
}).isRequired,
};

handleSave = () => {
Expand Down Expand Up @@ -93,10 +97,16 @@ class SpaceHeader extends Component {
}

renderDeleteButton() {
const { space } = this.props;
const {
space,
history: { goBack },
} = this.props;
const { saved, id } = space;
if (saved) {
return <DeleteButton spaceId={id} />;
const onSuccess = () => {
goBack();
};
return <DeleteButton spaceId={id} onSuccess={onSuccess} />;
}
return null;
}
Expand Down Expand Up @@ -203,9 +213,7 @@ class SpaceHeader extends Component {
}

const mapStateToProps = ({ Space, authentication }) => ({
space: Space.get('current')
.get('content')
.toJS(),
space: Space.get('current').get('content').toJS(),
userMode: authentication.getIn(['user', 'settings', 'userMode']),
});

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

const TranslatedComponent = withTranslation()(StyledComponent);

export default TranslatedComponent;
export default withRouter(TranslatedComponent);
30 changes: 5 additions & 25 deletions src/components/space/SpaceScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import MenuItem from '@material-ui/core/MenuItem/MenuItem';
import ListItemIcon from '@material-ui/core/ListItemIcon/ListItemIcon';
import ListItemText from '@material-ui/core/ListItemText/ListItemText';
import { withStyles } from '@material-ui/core';
import { withRouter } from 'react-router';
import Loader from '../common/Loader';
import PhaseComponent from '../phase/Phase';
import {
Expand All @@ -29,7 +28,6 @@ import {
} from '../../actions';
import './SpaceScreen.css';
import Styles from '../../Styles';
import { HOME_PATH } from '../../config/paths';
import SpaceHeader from './SpaceHeader';
import SpaceNotFound from './SpaceNotFound';
import MainMenu from '../common/MainMenu';
Expand Down Expand Up @@ -60,7 +58,6 @@ class SpaceScreen extends Component {
dispatchGetSpace: PropTypes.func.isRequired,
dispatchClearSpace: PropTypes.func.isRequired,
activity: PropTypes.bool.isRequired,
deleted: PropTypes.bool.isRequired,
classes: PropTypes.shape({
root: PropTypes.string.isRequired,
appBar: PropTypes.string.isRequired,
Expand All @@ -80,10 +77,6 @@ class SpaceScreen extends Component {
location: PropTypes.shape({
search: PropTypes.string.isRequired,
}).isRequired,
history: PropTypes.shape({
length: PropTypes.number.isRequired,
replace: PropTypes.func.isRequired,
}).isRequired,
recentSpaces: PropTypes.instanceOf(ImmList).isRequired,
dispatchSetSpaceAsRecent: PropTypes.func.isRequired,
};
Expand All @@ -104,18 +97,8 @@ class SpaceScreen extends Component {

componentDidUpdate() {
const { selected } = this.state;
const {
deleted,
phase,
history: { replace },
space,
recentSpaces,
dispatchSetSpaceAsRecent,
} = this.props;
// redirect to home if space is deleted
if (deleted) {
replace(HOME_PATH);
} else if (selected !== -1 && (!phase || phase.isEmpty())) {
const { phase, space, recentSpaces, dispatchSetSpaceAsRecent } = this.props;
if (selected !== -1 && (!phase || phase.isEmpty())) {
// eslint-disable-next-line react/no-did-update-set-state
this.setState({ selected: -1 });
}
Expand Down Expand Up @@ -145,7 +128,7 @@ class SpaceScreen extends Component {
this.setState({ openDrawer: false });
};

handlePhaseClicked = i => {
handlePhaseClicked = (i) => {
const { dispatchSelectPhase, space } = this.props;
const phases = space.get('phases');
dispatchSelectPhase(phases[i]);
Expand Down Expand Up @@ -251,12 +234,9 @@ class SpaceScreen extends Component {

const mapStateToProps = ({ Space, Phase, authentication }) => ({
space: Space.get('current').get('content'),
open: Space.get('current')
.get('menu')
.get('open'),
open: Space.get('current').get('menu').get('open'),
phase: Phase.get('current').get('content'),
activity: Boolean(Space.getIn(['current', 'activity']).size),
deleted: Space.get('current').get('deleted'),
recentSpaces: authentication.getIn(['user', 'recentSpaces']),
});

Expand All @@ -277,4 +257,4 @@ const StyledComponent = withStyles(Styles, { withTheme: true })(
ConnectedComponent
);

export default withRouter(StyledComponent);
export default StyledComponent;
12 changes: 0 additions & 12 deletions src/components/space/SyncAdvancedScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Loader from '../common/Loader';
import { clearSpacesForSync } from '../../actions';
import './SpaceScreen.css';
import Styles from '../../Styles';
import { HOME_PATH } from '../../config/paths';
import SpaceNotFound from './SpaceNotFound';
import { SYNC_SPACE_PROPERTIES } from '../../config/constants';
import SyncCancelButton from './sync/SyncCancelButton';
Expand Down Expand Up @@ -77,17 +76,6 @@ class SyncAdvancedScreen extends Component {
t: PropTypes.func.isRequired,
};

componentDidUpdate() {
const {
localSpace: { deleted },
history: { replace },
} = this.props;
// redirect to home if space is deleted
if (deleted) {
replace(HOME_PATH);
}
}

componentWillUnmount() {
const { dispatchClearSpaces } = this.props;
dispatchClearSpaces();
Expand Down
3 changes: 1 addition & 2 deletions src/components/space/SyncScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Styles from '../../Styles';
import Loader from '../common/Loader';
import { DEFAULT_SYNC_MODE, SYNC_MODES } from '../../config/constants';

const styles = theme => ({
const styles = (theme) => ({
...Styles(theme),
centerText: {
textAlign: 'center',
Expand All @@ -53,7 +53,6 @@ class SyncScreen extends Component {
id: PropTypes.string,
description: PropTypes.string,
name: PropTypes.string,
deleted: PropTypes.bool,
}),
remoteSpace: ImmutablePropTypes.contains({
id: PropTypes.string,
Expand Down

0 comments on commit 6301fed

Please sign in to comment.