Fix creating rooms from not found screen

This commit is contained in:
Robert Long 2022-02-23 15:36:38 -08:00
parent 42e2041d6f
commit 641b82dc45
3 changed files with 21 additions and 12 deletions

View file

@ -6,7 +6,7 @@ import { isLocalRoomId } from "../matrix-utils";
import { RoomNotFoundView } from "./RoomNotFoundView"; import { RoomNotFoundView } from "./RoomNotFoundView";
export function GroupCallLoader({ client, roomId, viaServers, children }) { export function GroupCallLoader({ client, roomId, viaServers, children }) {
const { loading, error, groupCall } = useLoadGroupCall( const { loading, error, groupCall, reload } = useLoadGroupCall(
client, client,
roomId, roomId,
viaServers viaServers
@ -29,7 +29,9 @@ export function GroupCallLoader({ client, roomId, viaServers, children }) {
error.message.indexOf("Failed to fetch alias") !== -1)) && error.message.indexOf("Failed to fetch alias") !== -1)) &&
isLocalRoomId(roomId) isLocalRoomId(roomId)
) { ) {
return <RoomNotFoundView client={client} roomId={roomId} />; return (
<RoomNotFoundView client={client} roomId={roomId} onReload={reload} />
);
} }
if (error) { if (error) {

View file

@ -8,7 +8,7 @@ import { Form } from "../form/Form";
import { useHistory } from "react-router-dom"; import { useHistory } from "react-router-dom";
import styles from "./RoomNotFoundView.module.css"; import styles from "./RoomNotFoundView.module.css";
export function RoomNotFoundView({ client, roomId }) { export function RoomNotFoundView({ client, roomId, onReload }) {
const history = useHistory(); const history = useHistory();
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [error, setError] = useState(); const [error, setError] = useState();
@ -21,11 +21,9 @@ export function RoomNotFoundView({ client, roomId }) {
setError(undefined); setError(undefined);
setLoading(true); setLoading(true);
const roomIdOrAlias = await createRoom(client, roomName); await createRoom(client, roomName);
if (roomIdOrAlias) { onReload();
history.push(`/room/${roomIdOrAlias}`);
}
} }
submit().catch((error) => { submit().catch((error) => {

View file

@ -1,4 +1,4 @@
import { useState, useEffect } from "react"; import { useState, useEffect, useCallback } from "react";
async function fetchGroupCall( async function fetchGroupCall(
client, client,
@ -41,14 +41,23 @@ export function useLoadGroupCall(client, roomId, viaServers) {
loading: true, loading: true,
error: undefined, error: undefined,
groupCall: undefined, groupCall: undefined,
reloadId: 0,
}); });
useEffect(() => { useEffect(() => {
setState({ loading: true }); setState({ loading: true });
fetchGroupCall(client, roomId, viaServers, 30000) fetchGroupCall(client, roomId, viaServers, 30000)
.then((groupCall) => setState({ loading: false, groupCall })) .then((groupCall) =>
.catch((error) => setState({ loading: false, error })); setState((prevState) => ({ ...prevState, loading: false, groupCall }))
}, [client, roomId]); )
.catch((error) =>
setState((prevState) => ({ ...prevState, loading: false, error }))
);
}, [client, roomId, state.reloadId]);
return state; const reload = useCallback(() => {
setState((prevState) => ({ ...prevState, reloadId: prevState.reloadId++ }));
}, []);
return { ...state, reload };
} }