Skip to content

Commit

Permalink
build(deps): remove unnecessary dependencies (cryostatio#1086)
Browse files Browse the repository at this point in the history
Signed-off-by: Thuan Vo <[email protected]>
  • Loading branch information
Thuan Vo authored Aug 14, 2023
1 parent 671d895 commit 8b8de35
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 342 deletions.
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,17 @@
"@testing-library/react": "^12.1.5",
"@testing-library/user-event": "^14.4.3",
"@types/enzyme": "^3.10.12",
"@types/enzyme-adapter-react-16": "^1.0.6",
"@types/jest": "^27.0.2",
"@types/js-base64": "3.3.1",
"@types/react-test-renderer": "^18.0.0",
"@types/selenium-webdriver": "^4.1.15",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.53.0",
"@wojtekmaj/enzyme-adapter-react-17": "^0.8.0",
"concurrently": "^8.2.0",
"css-loader": "^6.7.3",
"css-minimizer-webpack-plugin": "^4.2.2",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.7",
"enzyme-to-json": "^3.6.2",
"eslint": "^8.34.0",
"eslint-plugin-import": "^2.27.5",
Expand All @@ -77,7 +76,6 @@
"prop-types": "^15.7.2",
"raw-loader": "^4.0.2",
"react-axe": "^3.4.1",
"react-docgen-typescript-loader": "^3.7.2",
"react-router-dom": "^5.3.4",
"regenerator-runtime": "^0.13.11",
"rimraf": "^4.1.2",
Expand Down Expand Up @@ -121,7 +119,6 @@
"react-i18next": "^12.3.1",
"react-joyride": "^2.5.3",
"react-redux": "^8.0.5",
"react-router-last-location": "^2.0.1",
"semver": "^7.5.4",
"showdown": "^2.1.0"
},
Expand Down
45 changes: 16 additions & 29 deletions src/app/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/

import * as React from 'react';
import { Route, RouteComponentProps, Switch } from 'react-router-dom';
import { LastLocationProvider, useLastLocation } from 'react-router-last-location';
import { Route, RouteComponentProps, Switch, useLocation } from 'react-router-dom';
import About from './About/About';
import Archives from './Archives/Archives';
import CreateRecording from './CreateRecording/CreateRecording';
Expand Down Expand Up @@ -55,7 +54,6 @@ export interface IAppRoute {
path: string;
title: string;
description?: string; // non-empty description is used to filter routes for the NotFound page
isAsync?: boolean;
navGroup?: string;
featureLevel?: FeatureLevel;
children?: IAppRoute[];
Expand Down Expand Up @@ -208,20 +206,18 @@ const flatten = (routes: IAppRoute[]): IAppRoute[] => {
// a custom hook for sending focus to the primary content container
// after a view has loaded so that subsequent press of tab key
// sends focus directly to relevant content
const useA11yRouteChange = (isAsync: boolean) => {
const lastNavigation = useLastLocation();
const useA11yRouteChange = () => {
const { pathname } = useLocation();
React.useEffect(() => {
if (!isAsync && lastNavigation !== null) {
routeFocusTimer = accessibleRouteChangeHandler();
}
routeFocusTimer = accessibleRouteChangeHandler();
return () => {
window.clearTimeout(routeFocusTimer);
};
}, [isAsync, lastNavigation]);
}, [pathname]);
};

const RouteWithTitleUpdates = ({ component: Component, isAsync = false, path, title, ...rest }: IAppRoute) => {
useA11yRouteChange(isAsync);
const RouteWithTitleUpdates = ({ component: Component, title, path, ...rest }: IAppRoute) => {
useA11yRouteChange();
useDocumentTitle(title);

const renderFallback = React.useCallback((error: Error) => {
Expand Down Expand Up @@ -252,24 +248,15 @@ const AppRoutes: React.FC<AppRoutesProps> = (_) => {
const activeLevel = useFeatureLevel();

return (
<LastLocationProvider>
<Switch>
{flatten(routes)
.filter((r) => (loggedIn ? r.component !== Login : r.anonymous))
.filter((r) => r.featureLevel === undefined || r.featureLevel >= activeLevel)
.map(({ path, exact, component, title, isAsync }, idx) => (
<RouteWithTitleUpdates
path={path}
exact={exact}
component={component}
key={idx}
title={title}
isAsync={isAsync}
/>
))}
<PageNotFound title="404 Page Not Found" />
</Switch>
</LastLocationProvider>
<Switch>
{flatten(routes)
.filter((r) => (loggedIn ? r.component !== Login : r.anonymous))
.filter((r) => r.featureLevel === undefined || r.featureLevel >= activeLevel)
.map(({ path, exact, component, title }, idx) => (
<RouteWithTitleUpdates path={path} exact={exact} component={component} key={idx} title={title} />
))}
<PageNotFound title="404 Page Not Found" />
</Switch>
);
};

Expand Down
Loading

0 comments on commit 8b8de35

Please sign in to comment.