Skip to content
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

build(deps): remove unnecessary dependencies #1086

Merged
merged 1 commit into from
Aug 14, 2023
Merged
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
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
Loading