Fix creating rooms from not found screen
This commit is contained in:
parent
42e2041d6f
commit
641b82dc45
3 changed files with 21 additions and 12 deletions
|
@ -6,7 +6,7 @@ import { isLocalRoomId } from "../matrix-utils";
|
|||
import { RoomNotFoundView } from "./RoomNotFoundView";
|
||||
|
||||
export function GroupCallLoader({ client, roomId, viaServers, children }) {
|
||||
const { loading, error, groupCall } = useLoadGroupCall(
|
||||
const { loading, error, groupCall, reload } = useLoadGroupCall(
|
||||
client,
|
||||
roomId,
|
||||
viaServers
|
||||
|
@ -29,7 +29,9 @@ export function GroupCallLoader({ client, roomId, viaServers, children }) {
|
|||
error.message.indexOf("Failed to fetch alias") !== -1)) &&
|
||||
isLocalRoomId(roomId)
|
||||
) {
|
||||
return <RoomNotFoundView client={client} roomId={roomId} />;
|
||||
return (
|
||||
<RoomNotFoundView client={client} roomId={roomId} onReload={reload} />
|
||||
);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
|
|
|
@ -8,7 +8,7 @@ import { Form } from "../form/Form";
|
|||
import { useHistory } from "react-router-dom";
|
||||
import styles from "./RoomNotFoundView.module.css";
|
||||
|
||||
export function RoomNotFoundView({ client, roomId }) {
|
||||
export function RoomNotFoundView({ client, roomId, onReload }) {
|
||||
const history = useHistory();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState();
|
||||
|
@ -21,11 +21,9 @@ export function RoomNotFoundView({ client, roomId }) {
|
|||
setError(undefined);
|
||||
setLoading(true);
|
||||
|
||||
const roomIdOrAlias = await createRoom(client, roomName);
|
||||
await createRoom(client, roomName);
|
||||
|
||||
if (roomIdOrAlias) {
|
||||
history.push(`/room/${roomIdOrAlias}`);
|
||||
}
|
||||
onReload();
|
||||
}
|
||||
|
||||
submit().catch((error) => {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { useState, useEffect } from "react";
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
|
||||
async function fetchGroupCall(
|
||||
client,
|
||||
|
@ -41,14 +41,23 @@ export function useLoadGroupCall(client, roomId, viaServers) {
|
|||
loading: true,
|
||||
error: undefined,
|
||||
groupCall: undefined,
|
||||
reloadId: 0,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
setState({ loading: true });
|
||||
fetchGroupCall(client, roomId, viaServers, 30000)
|
||||
.then((groupCall) => setState({ loading: false, groupCall }))
|
||||
.catch((error) => setState({ loading: false, error }));
|
||||
}, [client, roomId]);
|
||||
.then((groupCall) =>
|
||||
setState((prevState) => ({ ...prevState, loading: false, groupCall }))
|
||||
)
|
||||
.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 };
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue