Skip to content

Commit 2da277c

Browse files
authored
Merge pull request processing#2295 from lindapaiste/chore/react-router-v5
Upgrade react-router from v4 to v5 and begin using hooks
2 parents baec197 + fd2a63f commit 2da277c

File tree

8 files changed

+77
-181
lines changed

8 files changed

+77
-181
lines changed

client/modules/IDE/pages/FullView.jsx

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import PropTypes from 'prop-types';
21
import React, { useEffect, useState } from 'react';
32
import Helmet from 'react-helmet';
43
import { useDispatch, useSelector } from 'react-redux';
4+
import { useParams } from 'react-router-dom';
55
import PreviewFrame from '../components/PreviewFrame';
66
import PreviewNav from '../../../components/PreviewNav';
77
import { getProject } from '../actions/project';
@@ -14,14 +14,15 @@ import {
1414
import useInterval from '../hooks/useInterval';
1515
import RootPage from '../../../components/RootPage';
1616

17-
function FullView(props) {
17+
function FullView() {
1818
const dispatch = useDispatch();
1919
const project = useSelector((state) => state.project);
2020
const [isRendered, setIsRendered] = useState(false);
21+
const params = useParams();
2122

2223
useEffect(() => {
23-
dispatch(getProject(props.params.project_id, props.params.username));
24-
}, []);
24+
dispatch(getProject(params.project_id, params.username));
25+
}, [params]);
2526

2627
useEffect(() => {
2728
// if (isRendered) prevents startSketch() from being called twice
@@ -64,7 +65,7 @@ function FullView(props) {
6465
}}
6566
project={{
6667
name: project.name,
67-
id: props.params.project_id
68+
id: params.project_id
6869
}}
6970
/>
7071
<main className="preview-frame-holder">
@@ -74,11 +75,4 @@ function FullView(props) {
7475
);
7576
}
7677

77-
FullView.propTypes = {
78-
params: PropTypes.shape({
79-
project_id: PropTypes.string,
80-
username: PropTypes.string
81-
}).isRequired
82-
};
83-
8478
export default FullView;

client/modules/IDE/pages/IDEView.jsx

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import PropTypes from 'prop-types';
22
import React from 'react';
3-
import { Prompt } from 'react-router-dom';
3+
import { useLocation, Prompt } from 'react-router-dom';
44
import { bindActionCreators } from 'redux';
55
import { connect, useSelector } from 'react-redux';
66
import { useTranslation, withTranslation } from 'react-i18next';
@@ -49,11 +49,13 @@ function isOverlay(pathname) {
4949
return pathname === '/about' || pathname === '/feedback';
5050
}
5151

52-
function WarnIfUnsavedChanges({ currentLocation }) {
52+
function WarnIfUnsavedChanges() {
5353
const hasUnsavedChanges = useSelector((state) => state.ide.unsavedChanges);
5454

5555
const { t } = useTranslation();
5656

57+
const currentLocation = useLocation();
58+
5759
return (
5860
<Prompt
5961
when={hasUnsavedChanges}
@@ -72,12 +74,6 @@ function WarnIfUnsavedChanges({ currentLocation }) {
7274
);
7375
}
7476

75-
WarnIfUnsavedChanges.propTypes = {
76-
currentLocation: PropTypes.shape({
77-
pathname: PropTypes.string
78-
}).isRequired
79-
};
80-
8177
class IDEView extends React.Component {
8278
constructor(props) {
8379
super(props);

client/modules/IDE/pages/Legal.jsx

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useState, useEffect } from 'react';
2-
import PropTypes from 'prop-types';
2+
import { useHistory, useLocation } from 'react-router-dom';
33
import { Tab, Tabs, TabList, TabPanel } from 'react-tabs';
44
import styled from 'styled-components';
55
import { useTranslation } from 'react-i18next';
@@ -8,7 +8,6 @@ import TermsOfUse from './TermsOfUse';
88
import CodeOfConduct from './CodeOfConduct';
99
import RootPage from '../../../components/RootPage';
1010
import Nav from '../../../components/Nav';
11-
import browserHistory from '../../../browserHistory';
1211
import { remSize, prop } from '../../../theme';
1312

1413
const StyledTabList = styled(TabList)`
@@ -29,9 +28,12 @@ const TabTitle = styled.p`
2928
}
3029
`;
3130

32-
function Legal({ location }) {
31+
function Legal() {
3332
const [selectedIndex, setSelectedIndex] = useState(0);
3433
const { t } = useTranslation();
34+
const location = useLocation();
35+
const history = useHistory();
36+
3537
useEffect(() => {
3638
if (location.pathname === '/privacy-policy') {
3739
setSelectedIndex(0);
@@ -46,13 +48,13 @@ function Legal({ location }) {
4648
if (index === lastIndex) return;
4749
if (index === 0) {
4850
setSelectedIndex(0);
49-
browserHistory.push('/privacy-policy');
51+
history.push('/privacy-policy');
5052
} else if (index === 1) {
5153
setSelectedIndex(1);
52-
browserHistory.push('/terms-of-use');
54+
history.push('/terms-of-use');
5355
} else if (index === 2) {
5456
setSelectedIndex(2);
55-
browserHistory.push('/code-of-conduct');
57+
history.push('/code-of-conduct');
5658
}
5759
}
5860

@@ -85,10 +87,4 @@ function Legal({ location }) {
8587
);
8688
}
8789

88-
Legal.propTypes = {
89-
location: PropTypes.shape({
90-
pathname: PropTypes.string
91-
}).isRequired
92-
};
93-
9490
export default Legal;

client/modules/Mobile/MobileDashboardView.jsx

+5-16
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from 'react';
2-
import PropTypes from 'prop-types';
32
import styled from 'styled-components';
43
import { useSelector } from 'react-redux';
5-
import { withRouter } from 'react-router-dom';
4+
import { useLocation, useParams } from 'react-router-dom';
65
import { useTranslation } from 'react-i18next';
76

87
import Screen from '../../components/mobile/MobileScreen';
@@ -178,10 +177,10 @@ const NavItem = styled.li`
178177
const renderPanel = (name, props) =>
179178
((Component) => Component && <Component {...props} mobile />)(Panels[name]);
180179

181-
const MobileDashboard = ({ params, location }) => {
180+
const MobileDashboard = () => {
182181
const user = useSelector((state) => state.user);
183-
const { username: paramsUsername } = params;
184-
const { pathname } = location;
182+
const { username: paramsUsername } = useParams();
183+
const { pathname } = useLocation();
185184
const { t } = useTranslation();
186185

187186
const Tabs = Object.keys(Panels);
@@ -253,14 +252,4 @@ const MobileDashboard = ({ params, location }) => {
253252
);
254253
};
255254

256-
MobileDashboard.propTypes = {
257-
location: PropTypes.shape({
258-
pathname: PropTypes.string.isRequired
259-
}).isRequired,
260-
params: PropTypes.shape({
261-
username: PropTypes.string.isRequired
262-
})
263-
};
264-
MobileDashboard.defaultProps = { params: {} };
265-
266-
export default withRouter(MobileDashboard);
255+
export default MobileDashboard;

client/modules/User/pages/AccountView.jsx

+6-13
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
import PropTypes from 'prop-types';
21
import React from 'react';
32
import { useDispatch, useSelector } from 'react-redux';
43
import { Tab, Tabs, TabList, TabPanel } from 'react-tabs';
54
import { Helmet } from 'react-helmet';
65
import { useTranslation } from 'react-i18next';
7-
import { withRouter } from 'react-router-dom';
6+
import { useHistory, useLocation } from 'react-router-dom';
87
import { parse } from 'query-string';
98
import { createApiKey, removeApiKey } from '../actions';
109
import AccountForm from '../components/AccountForm';
1110
import SocialAuthButton from '../components/SocialAuthButton';
1211
import APIKeyForm from '../components/APIKeyForm';
13-
import browserHistory from '../../../browserHistory';
1412
import Nav from '../../../components/Nav';
1513
import ErrorModal from '../../IDE/components/ErrorModal';
1614
import Overlay from '../../App/components/Overlay';
@@ -45,16 +43,18 @@ function SocialLoginPanel() {
4543
);
4644
}
4745

48-
function AccountView({ location }) {
46+
function AccountView() {
4947
const { t } = useTranslation();
5048

49+
const location = useLocation();
5150
const queryParams = parse(location.search);
5251
const showError = !!queryParams.error;
5352
const errorType = queryParams.error;
5453
const accessTokensUIEnabled = window.process.env.UI_ACCESS_TOKEN_ENABLED;
5554

5655
const apiKeys = useSelector((state) => state.user.apiKeys);
5756
const dispatch = useDispatch();
57+
const history = useHistory();
5858

5959
return (
6060
<div className="account-settings__container">
@@ -70,7 +70,7 @@ function AccountView({ location }) {
7070
title={t('ErrorModal.LinkTitle')}
7171
ariaLabel={t('ErrorModal.LinkTitle')}
7272
closeOverlay={() => {
73-
browserHistory.push(location.pathname);
73+
history.push(location.pathname);
7474
}}
7575
>
7676
<ErrorModal type="oauthError" service={errorType} />
@@ -119,11 +119,4 @@ function AccountView({ location }) {
119119
);
120120
}
121121

122-
AccountView.propTypes = {
123-
location: PropTypes.shape({
124-
search: PropTypes.string.isRequired,
125-
pathname: PropTypes.string.isRequired
126-
}).isRequired
127-
};
128-
129-
export default withRouter(AccountView);
122+
export default AccountView;

client/modules/User/pages/NewPasswordView.jsx

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
import PropTypes from 'prop-types';
21
import React, { useEffect } from 'react';
32
import classNames from 'classnames';
43
import { useDispatch, useSelector } from 'react-redux';
54
import { Helmet } from 'react-helmet';
65
import { useTranslation } from 'react-i18next';
6+
import { useParams } from 'react-router-dom';
77
import NewPasswordForm from '../components/NewPasswordForm';
88
import { validateResetPasswordToken } from '../actions';
99
import Nav from '../../../components/Nav';
1010
import RootPage from '../../../components/RootPage';
1111

12-
function NewPasswordView(props) {
12+
function NewPasswordView() {
1313
const { t } = useTranslation();
14-
const resetPasswordToken = props.params.reset_password_token;
14+
const params = useParams();
15+
const resetPasswordToken = params.reset_password_token;
1516
const resetPasswordInvalid = useSelector(
1617
(state) => state.user.resetPasswordInvalid
1718
);
@@ -48,10 +49,4 @@ function NewPasswordView(props) {
4849
);
4950
}
5051

51-
NewPasswordView.propTypes = {
52-
params: PropTypes.shape({
53-
reset_password_token: PropTypes.string
54-
}).isRequired
55-
};
56-
5752
export default NewPasswordView;

0 commit comments

Comments
 (0)