Skip to content

Commit

Permalink
Handle promises
Browse files Browse the repository at this point in the history
  • Loading branch information
hughns committed Jan 8, 2025
1 parent 5233ab6 commit 882a74d
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/ClientContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export const ClientProvider: FC<Props> = ({ children }) => {
await client.clearStores();
clearSession();
setInitClientState(null);
navigate("/");
await navigate("/");
PosthogAnalytics.instance.setRegistrationType(RegistrationType.Guest);
}, [navigate, initClientState?.client]);

Expand Down
5 changes: 4 additions & 1 deletion src/UserMenuContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Please see LICENSE in the repository root for full details.

import { type FC, useCallback, useState } from "react";
import { useNavigate, useLocation } from "react-router-dom";
import { logger } from "matrix-js-sdk/src/logger";

import { useClientLegacy } from "./ClientContext";
import { useProfile } from "./profile/useProfile";
Expand Down Expand Up @@ -45,7 +46,9 @@ export const UserMenuContainer: FC<Props> = ({ preventNavigation = false }) => {
logout?.();
break;
case "login":
navigate("/login", { state: { from: location } });
navigate("/login", { state: { from: location } })?.catch((error) =>
logger.error("Failed to navigate to login", error),
);
break;
}
},
Expand Down
6 changes: 3 additions & 3 deletions src/auth/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const LoginPage: FC = () => {
}

login(homeserver, usernameRef.current.value, passwordRef.current.value)
.then(([client, session]) => {
.then(async ([client, session]) => {
if (!setClient) {
return;
}
Expand All @@ -61,9 +61,9 @@ export const LoginPage: FC = () => {
if (locationState && locationState.from) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
navigate(locationState.from);
await navigate(locationState.from);
} else {
navigate("/");
await navigate("/");
}
PosthogAnalytics.instance.eventLogin.track();
})
Expand Down
10 changes: 6 additions & 4 deletions src/auth/RegisterPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ export const RegisterPage: FC = () => {
};

submit()
.then(() => {
.then(async () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (location.state?.from) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
navigate(location.state?.from);
await navigate(location.state?.from);
} else {
navigate("/");
await navigate("/");
}
})
.catch((error) => {
Expand Down Expand Up @@ -141,7 +141,9 @@ export const RegisterPage: FC = () => {

useEffect(() => {
if (!loading && authenticated && !passwordlessUser && !registering) {
navigate("/");
navigate("/")?.catch((error) => {
logger.error("Failed to navigate to /", error);
});
}
}, [loading, navigate, authenticated, passwordlessUser, registering]);

Expand Down
6 changes: 4 additions & 2 deletions src/home/RegisteredView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const RegisteredView: FC<Props> = ({ client }) => {
if (!createRoomResult.password)
throw new Error("Failed to create room with shared secret");

navigate(
await navigate(
getRelativeRoomUrl(
createRoomResult.roomId,
{ kind: E2eeType.SHARED_KEY, secret: createRoomResult.password },
Expand Down Expand Up @@ -106,7 +106,9 @@ export const RegisteredView: FC<Props> = ({ client }) => {

const [existingAlias, setExistingAlias] = useState<string>();
const onJoinExistingRoom = useCallback(() => {
navigate(`/${existingAlias}`);
navigate(`/${existingAlias}`)?.catch((error) => {
logger.error("Failed to navigate to existing alias", error);
});
}, [navigate, existingAlias]);

return (
Expand Down
6 changes: 4 additions & 2 deletions src/home/UnauthenticatedView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ export const UnauthenticatedView: FC = () => {
setOnFinished(() => {
setClient({ client, session });
const aliasLocalpart = roomAliasLocalpartFromRoomName(roomName);
navigate(`/${aliasLocalpart}`);
navigate(`/${aliasLocalpart}`)?.catch((error) => {
logger.error("Failed to navigate to alias localpart", error);
});
});

setLoading(false);
Expand All @@ -110,7 +112,7 @@ export const UnauthenticatedView: FC = () => {
throw new Error("Failed to create room with shared secret");

setClient({ client, session });
navigate(
await navigate(
getRelativeRoomUrl(
createRoomResult.roomId,
{ kind: E2eeType.SHARED_KEY, secret: createRoomResult.password },
Expand Down
5 changes: 4 additions & 1 deletion src/room/CallEndedView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { type MatrixClient } from "matrix-js-sdk/src/client";
import { Trans, useTranslation } from "react-i18next";
import { Button, Heading, Text } from "@vector-im/compound-web";
import { useNavigate } from "react-router-dom";
import { logger } from "matrix-js-sdk/src/logger";

import styles from "./CallEndedView.module.css";
import feedbackStyle from "../input/FeedbackInput.module.css";
Expand Down Expand Up @@ -76,7 +77,9 @@ export const CallEndedView: FC<Props> = ({
setSurveySubmitted(true);
} else if (!confineToRoom) {
// if the user already has an account immediately go back to the home screen
navigate("/");
navigate("/")?.catch((error) => {
logger.error("Failed to navigate to /", error);
});
}
}, 1000);
}, 1000);
Expand Down
4 changes: 2 additions & 2 deletions src/room/GroupCallView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,13 @@ export const GroupCallView: FC<Props> = ({
sendInstantly && audioPromise ? audioPromise : undefined,
)
// Only sends matrix leave event. The Livekit session will disconnect once the ActiveCall-view unmounts.
.then(() => {
.then(async () => {
if (
!isPasswordlessUser &&
!confineToRoom &&
!PosthogAnalytics.instance.isEnabled()
) {
navigate("/");
await navigate("/");
}
})
.catch((e) => {
Expand Down
6 changes: 5 additions & 1 deletion src/room/LobbyView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ export const LobbyView: FC<Props> = ({
);

const navigate = useNavigate();
const onLeaveClick = useCallback(() => navigate("/"), [navigate]);
const onLeaveClick = useCallback(() => {
navigate("/")?.catch((error) => {
logger.error("Failed to navigate to /", error);
});
}, [navigate]);

const recentsButtonInFooter = useMediaQuery("(max-height: 500px)");
const recentsButton = !confineToRoom && (
Expand Down

0 comments on commit 882a74d

Please sign in to comment.