11import React , { ReactNode } from 'react' ;
22import { useParams } from 'react-router-dom' ;
33import { useAtom , useAtomValue } from 'jotai' ;
4+ import { Room } from 'matrix-js-sdk' ;
45import { useSelectedRoom } from '../../../hooks/router/useSelectedRoom' ;
56import { IsDirectRoomProvider , RoomProvider } from '../../../hooks/useRoom' ;
67import { useMatrixClient } from '../../../hooks/useMatrixClient' ;
@@ -13,6 +14,8 @@ import { useSearchParamsViaServers } from '../../../hooks/router/useSearchParams
1314import { mDirectAtom } from '../../../state/mDirectList' ;
1415import { settingsAtom } from '../../../state/settings' ;
1516import { useSetting } from '../../../state/hooks/settings' ;
17+ import { useRoomReady } from '../../../hooks/useRoomReady' ;
18+ import { RoomLoading } from '../../../components/RoomLoading' ;
1619
1720export function SpaceRouteRoomProvider ( { children } : { children : ReactNode } ) {
1821 const mx = useMatrixClient ( ) ;
@@ -42,7 +45,9 @@ export function SpaceRouteRoomProvider({ children }: { children: ReactNode }) {
4245 // allow to view space timeline
4346 return (
4447 < RoomProvider key = { room . roomId } value = { room } >
45- < IsDirectRoomProvider value = { mDirects . has ( room . roomId ) } > { children } </ IsDirectRoomProvider >
48+ < IsDirectRoomProvider value = { mDirects . has ( room . roomId ) } >
49+ < RoomReadyGate room = { room } > { children } </ RoomReadyGate >
50+ </ IsDirectRoomProvider >
4651 </ RoomProvider >
4752 ) ;
4853 }
@@ -68,7 +73,15 @@ export function SpaceRouteRoomProvider({ children }: { children: ReactNode }) {
6873
6974 return (
7075 < RoomProvider key = { room . roomId } value = { room } >
71- < IsDirectRoomProvider value = { mDirects . has ( room . roomId ) } > { children } </ IsDirectRoomProvider >
76+ < IsDirectRoomProvider value = { mDirects . has ( room . roomId ) } >
77+ < RoomReadyGate room = { room } > { children } </ RoomReadyGate >
78+ </ IsDirectRoomProvider >
7279 </ RoomProvider >
7380 ) ;
7481}
82+
83+ function RoomReadyGate ( { room, children } : { room : Room ; children : ReactNode } ) {
84+ const ready = useRoomReady ( room ) ;
85+ if ( ! ready ) return < RoomLoading /> ;
86+ return < > { children } </ > ;
87+ }
0 commit comments