Skip to content

[WIP] Upgrade react-router from "^3.2.6" to "^6.8.1" #2135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/common/Button.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';

import { remSize, prop } from '../theme';

Expand Down
10 changes: 4 additions & 6 deletions client/components/Nav.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import PropTypes from 'prop-types';
import React from 'react';
import { connect } from 'react-redux';
import { withRouter } from 'react-router';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import classNames from 'classnames';
import { withTranslation } from 'react-i18next';
import { languageKeyToLabel } from '../i18n';
Expand All @@ -17,6 +16,7 @@ import { logoutUser } from '../modules/User/actions';

import getConfig from '../utils/getConfig';
import { metaKeyName, metaKey } from '../utils/metaKey';
import { withRouter } from '../utils/router-compatibilty';
import { getIsUserOwner } from '../modules/IDE/selectors/users';
import { selectSketchPath } from '../modules/IDE/selectors/project';

Expand Down Expand Up @@ -100,12 +100,12 @@ class Nav extends React.PureComponent {
}

handleNew() {
const { unsavedChanges, warnIfUnsavedChanges } = this.props;
const { unsavedChanges } = this.props;
if (!unsavedChanges) {
this.props.showToast(1500);
this.props.setToastText('Toast.OpenedNewSketch');
this.props.newProject();
} else if (warnIfUnsavedChanges && warnIfUnsavedChanges()) {
} else if (window.confirm(this.props.t('Nav.WarningUnsavedChanges'))) {
this.props.showToast(1500);
this.props.setToastText('Toast.OpenedNewSketch');
this.props.newProject();
Expand Down Expand Up @@ -968,7 +968,6 @@ Nav.propTypes = {
showShareModal: PropTypes.func.isRequired,
showErrorModal: PropTypes.func.isRequired,
unsavedChanges: PropTypes.bool.isRequired,
warnIfUnsavedChanges: PropTypes.func,
showKeyboardShortcutModal: PropTypes.func.isRequired,
cmController: PropTypes.shape({
tidyCode: PropTypes.func,
Expand Down Expand Up @@ -1002,7 +1001,6 @@ Nav.defaultProps = {
},
cmController: {},
layout: 'project',
warnIfUnsavedChanges: undefined,
params: {
username: undefined
},
Expand Down
2 changes: 1 addition & 1 deletion client/components/PreviewNav.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PropTypes from 'prop-types';
import React from 'react';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next';

import LogoIcon from '../images/p5js-logo-small.svg';
Expand Down
42 changes: 18 additions & 24 deletions client/components/createRedirectWithUsername.jsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
import PropTypes from 'prop-types';
import React from 'react';
import { connect } from 'react-redux';
import { browserHistory } from 'react-router';
import { useSelector } from 'react-redux';
import { Navigate } from 'react-router-dom';

const RedirectToUser = ({ username, url = '/:username/sketches' }) => {
React.useEffect(() => {
if (username == null) {
return;
}

browserHistory.replace(url.replace(':username', username));
}, [username]);

return null;
/**
* Sets the current username to the `:username` template in the provided URL,
* eg. `/:username/sketches` => `/p5/sketches`.
*/
const RedirectToUser = ({ url = '/:username/sketches' }) => {
const username = useSelector((state) =>
state.user ? state.user.username : null
);
return username ? (
<Navigate to={url.replace(':username', username)} replace />
) : null;
};

function mapStateToProps(state) {
return {
username: state.user ? state.user.username : null
};
}

const ConnectedRedirectToUser = connect(mapStateToProps)(RedirectToUser);

const createRedirectWithUsername = (url) => (props) => (
<ConnectedRedirectToUser {...props} url={url} />
);
RedirectToUser.propTypes = {
url: PropTypes.string.isRequired
};

export default createRedirectWithUsername;
export default RedirectToUser;
2 changes: 1 addition & 1 deletion client/components/mobile/Tab.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styled from 'styled-components';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import { prop, remSize } from '../../theme';

export default styled(Link)`
Expand Down
7 changes: 3 additions & 4 deletions client/index.integration.test.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { setupServer } from 'msw/node';
import { rest } from 'msw';
import React from 'react';
import { Router, browserHistory } from 'react-router';
import { RouterProvider } from 'react-router-dom';
import router from './router';

import { reduxRender, act, waitFor, screen, within } from './test-utils';
import configureStore from './store';
import routes from './routes';
import * as Actions from './modules/User/actions';
import { userResponse } from './testData/testServerResponses';

// setup for the app
const history = browserHistory;
const initialState = window.__INITIAL_STATE__;
const store = configureStore(initialState);

Expand Down Expand Up @@ -57,7 +56,7 @@ document.createRange = () => {
describe('index.jsx integration', () => {
// the subject under test
const subject = () =>
reduxRender(<Router history={history} routes={routes(store)} />, { store });
reduxRender(<RouterProvider router={router} />, { store });

// spy on this function and wait for it to be called before making assertions
const spy = jest.spyOn(Actions, 'getUser');
Expand Down
7 changes: 3 additions & 4 deletions client/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import React, { Suspense } from 'react';
import { render } from 'react-dom';
import { hot } from 'react-hot-loader/root';
import { Provider } from 'react-redux';
import { Router, browserHistory } from 'react-router';
import { RouterProvider } from 'react-router-dom';

import configureStore from './store';
import routes from './routes';
import router from './router';
import ThemeProvider from './modules/App/components/ThemeProvider';
import Loader from './modules/App/components/loader';
import './i18n';
Expand All @@ -15,15 +15,14 @@ require('./styles/main.scss');
// Load the p5 png logo, so that webpack will use it
require('./images/p5js-square-logo.png');

const history = browserHistory;
const initialState = window.__INITIAL_STATE__;

const store = configureStore(initialState);

const App = () => (
<Provider store={store}>
<ThemeProvider>
<Router history={history} routes={routes(store)} />
<RouterProvider router={router} />
</ThemeProvider>
</Provider>
);
Expand Down
9 changes: 5 additions & 4 deletions client/modules/App/components/Overlay.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import PropTypes from 'prop-types';
import React from 'react';
import { browserHistory } from 'react-router';
import { withTranslation } from 'react-i18next';

import ExitIcon from '../../../images/exit.svg';
import { withRouter } from '../../../utils/router-compatibilty';

class Overlay extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -55,7 +55,7 @@ class Overlay extends React.Component {
return;

if (!this.props.closeOverlay) {
browserHistory.push(this.props.previousPath);
this.props.navigate(this.props.previousPath);
} else {
this.props.closeOverlay();
}
Expand Down Expand Up @@ -105,7 +105,8 @@ Overlay.propTypes = {
ariaLabel: PropTypes.string,
previousPath: PropTypes.string,
isFixedHeight: PropTypes.bool,
t: PropTypes.func.isRequired
t: PropTypes.func.isRequired,
navigate: PropTypes.func.isRequired
};

Overlay.defaultProps = {
Expand All @@ -118,4 +119,4 @@ Overlay.defaultProps = {
isFixedHeight: false
};

export default withTranslation()(Overlay);
export default withRouter(withTranslation()(Overlay));
4 changes: 2 additions & 2 deletions client/modules/IDE/actions/collections.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { browserHistory } from 'react-router';
import { navigate } from '../../../router';
import apiClient from '../../../utils/apiClient';
import * as ActionTypes from '../../../constants';
import { startLoader, stopLoader } from './loader';
Expand Down Expand Up @@ -56,7 +56,7 @@ export function createCollection(collection) {
const pathname = `/${newCollection.owner.username}/collections/${newCollection.id}`;
const location = { pathname, state: { skipSavingPath: true } };

browserHistory.push(location);
navigate(location);
})
.catch((error) => {
const { response } = error;
Expand Down
8 changes: 4 additions & 4 deletions client/modules/IDE/actions/project.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { browserHistory } from 'react-router';
import objectID from 'bson-objectid';
import each from 'async/each';
import isEqual from 'lodash/isEqual';
import { navigate } from '../../../router';
import apiClient from '../../../utils/apiClient';
import getConfig from '../../../utils/getConfig';
import * as ActionTypes from '../../../constants';
Expand Down Expand Up @@ -214,7 +214,7 @@ export function saveProject(

dispatch(setNewProject(synchedProject));
dispatch(setUnsavedChanges(false));
browserHistory.push(
navigate(
`/${response.data.user.username}/sketches/${response.data.id}`
);

Expand Down Expand Up @@ -271,7 +271,7 @@ export function resetProject() {

export function newProject() {
setTimeout(() => {
browserHistory.push('/');
navigate('/');
}, 0);
return resetProject();
}
Expand Down Expand Up @@ -334,7 +334,7 @@ export function cloneProject(project) {
apiClient
.post('/projects', formParams)
.then((response) => {
browserHistory.push(
navigate(
`/${response.data.user.username}/sketches/${response.data.id}`
);
dispatch(setNewProject(response.data));
Expand Down
2 changes: 1 addition & 1 deletion client/modules/IDE/components/About.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { useSelector } from 'react-redux';
import { Helmet } from 'react-helmet';
import { useTranslation } from 'react-i18next';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import SquareLogoIcon from '../../../images/p5js-square-logo.svg';
// import PlayIcon from '../../../images/play.svg';
import AsteriskIcon from '../../../images/p5-asterisk.svg';
Expand Down
2 changes: 1 addition & 1 deletion client/modules/IDE/components/AssetList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import { Helmet } from 'react-helmet';
import prettyBytes from 'pretty-bytes';
import { withTranslation } from 'react-i18next';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types';
import React from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import { bindActionCreators } from 'redux';
import { withTranslation } from 'react-i18next';
import * as ProjectActions from '../../actions/project';
Expand Down
2 changes: 1 addition & 1 deletion client/modules/IDE/components/ErrorModal.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PropTypes from 'prop-types';
import React from 'react';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next';

const ErrorModal = ({ type, service, closeModal }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next';

import Icons from './Icons';
Expand Down
2 changes: 1 addition & 1 deletion client/modules/IDE/components/SketchList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import { Helmet } from 'react-helmet';
import { withTranslation } from 'react-i18next';
import { connect } from 'react-redux';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import { bindActionCreators } from 'redux';
import classNames from 'classnames';
import slugify from 'slugify';
Expand Down
2 changes: 1 addition & 1 deletion client/modules/IDE/components/Toolbar.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types';
import React from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import classNames from 'classnames';
import { withTranslation } from 'react-i18next';
import * as IDEActions from '../actions/ide';
Expand Down
2 changes: 1 addition & 1 deletion client/modules/IDE/components/UploadFileModal.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import prettyBytes from 'pretty-bytes';
import getConfig from '../../../utils/getConfig';
Expand Down
16 changes: 5 additions & 11 deletions client/modules/IDE/pages/FullView.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types';
import React, { useEffect, useState } from 'react';
import Helmet from 'react-helmet';
import { useDispatch, useSelector } from 'react-redux';
import { useParams } from 'react-router-dom';
import PreviewFrame from '../components/PreviewFrame';
import PreviewNav from '../../../components/PreviewNav';
import { getProject } from '../actions/project';
Expand All @@ -14,13 +14,14 @@ import {
import useInterval from '../hooks/useInterval';
import RootPage from '../../../components/RootPage';

function FullView(props) {
function FullView() {
const params = useParams();
const dispatch = useDispatch();
const project = useSelector((state) => state.project);
const [isRendered, setIsRendered] = useState(false);

useEffect(() => {
dispatch(getProject(props.params.project_id, props.params.username));
dispatch(getProject(params.project_id, params.username));
}, []);

useEffect(() => {
Expand Down Expand Up @@ -64,7 +65,7 @@ function FullView(props) {
}}
project={{
name: project.name,
id: props.params.project_id
id: params.project_id
}}
/>
<main className="preview-frame-holder">
Expand All @@ -74,11 +75,4 @@ function FullView(props) {
);
}

FullView.propTypes = {
params: PropTypes.shape({
project_id: PropTypes.string,
username: PropTypes.string
}).isRequired
};

export default FullView;
Loading