refactor: simplify Room loading
This commit is contained in:
parent
7cb7e5fdd5
commit
96f2991209
@ -3,14 +3,15 @@ import Button from '@mui/material/Button'
|
|||||||
import Typography from '@mui/material/Typography'
|
import Typography from '@mui/material/Typography'
|
||||||
|
|
||||||
import { usePeerRoom, usePeerRoomAction, PeerActions } from 'hooks/usePeerRoom'
|
import { usePeerRoom, usePeerRoomAction, PeerActions } from 'hooks/usePeerRoom'
|
||||||
import { PeerRoom } from 'services/PeerRoom'
|
|
||||||
|
|
||||||
interface RoomProps {
|
export function Room() {
|
||||||
peerRoom: PeerRoom
|
const { roomId = '' } = useParams()
|
||||||
roomId: string
|
|
||||||
}
|
const peerRoom = usePeerRoom({
|
||||||
|
appId: `${encodeURI(window.location.origin)}_${process.env.REACT_APP_NAME}`,
|
||||||
|
roomId,
|
||||||
|
})
|
||||||
|
|
||||||
function Room({ peerRoom, roomId }: RoomProps) {
|
|
||||||
const [sendMessage, receiveMessage] = usePeerRoomAction<string>(
|
const [sendMessage, receiveMessage] = usePeerRoomAction<string>(
|
||||||
peerRoom,
|
peerRoom,
|
||||||
PeerActions.MESSAGE
|
PeerActions.MESSAGE
|
||||||
@ -37,20 +38,3 @@ function Room({ peerRoom, roomId }: RoomProps) {
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function RoomLoader() {
|
|
||||||
const { roomId = '' } = useParams()
|
|
||||||
|
|
||||||
const peerRoom = usePeerRoom({
|
|
||||||
appId: `${encodeURI(window.location.origin)}_${process.env.REACT_APP_NAME}`,
|
|
||||||
roomId,
|
|
||||||
})
|
|
||||||
|
|
||||||
if (peerRoom) {
|
|
||||||
return <Room peerRoom={peerRoom} roomId={roomId} />
|
|
||||||
} else {
|
|
||||||
return <>Loading...</>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export { RoomLoader as Room }
|
|
||||||
|
Loading…
Reference in New Issue
Block a user