Refactor RealmContext to use React Router v6 (#4182)

This commit is contained in:
Jon Koops 2023-01-13 16:10:29 +01:00 committed by GitHub
parent 23e1aa54a7
commit 66cf2ad368
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,10 +1,8 @@
import { FunctionComponent, useEffect, useMemo } from "react"; import { FunctionComponent, useEffect, useMemo } from "react";
import { useRouteMatch } from "react-router-dom"; import { useMatch } from "react-router-dom-v5-compat";
import { RecentUsed } from "../../components/realm-selector/recent-used"; import { RecentUsed } from "../../components/realm-selector/recent-used";
import { import { DashboardRouteWithRealm } from "../../dashboard/routes/Dashboard";
DashboardParams,
DashboardRouteWithRealm,
} from "../../dashboard/routes/Dashboard";
import environment from "../../environment"; import environment from "../../environment";
import { createNamedContext } from "../../utils/createNamedContext"; import { createNamedContext } from "../../utils/createNamedContext";
import useRequiredContext from "../../utils/useRequiredContext"; import useRequiredContext from "../../utils/useRequiredContext";
@ -22,9 +20,11 @@ export const RealmContext = createNamedContext<RealmContextType | undefined>(
export const RealmContextProvider: FunctionComponent = ({ children }) => { export const RealmContextProvider: FunctionComponent = ({ children }) => {
const { adminClient } = useAdminClient(); const { adminClient } = useAdminClient();
const recentUsed = useMemo(() => new RecentUsed(), []); const recentUsed = useMemo(() => new RecentUsed(), []);
const routeMatch = useRouteMatch<DashboardParams>( const routeMatch = useMatch({
DashboardRouteWithRealm.path path: DashboardRouteWithRealm.path,
); end: false,
});
const realmParam = routeMatch?.params.realm; const realmParam = routeMatch?.params.realm;
const realm = useMemo( const realm = useMemo(
() => realmParam ?? environment.loginRealm, () => realmParam ?? environment.loginRealm,