Potentially fixes bug when roomId changes

This commit is contained in:
Steve Ruiz 2021-07-07 10:50:12 +01:00
parent 5334f41e1d
commit be359e6406
2 changed files with 11 additions and 7 deletions

View file

@ -3,12 +3,12 @@ import { useEffect } from 'react'
import state from 'state'
import coopState from 'state/coop/coop-state'
export default function useLoadOnMount(roomId: string = undefined) {
export default function useLoadOnMount(roomId?: string) {
useEffect(() => {
if ('fonts' in document) {
const fonts = (document as any).fonts
fonts.load('12px Verveine Regular', 'Fonts are loaded!').then(() => {
state.send('MOUNTED')
state.send('MOUNTED', { roomId })
if (roomId !== undefined) {
state.send('RT_LOADED_ROOM', { id: roomId })
@ -20,7 +20,7 @@ export default function useLoadOnMount(roomId: string = undefined) {
}
return () => {
state.send('UNMOUNTED').send('RT_UNLOADED_ROOM', { id: roomId })
state.send('UNMOUNTED', { roomId })
coopState.send('LEFT_ROOM', { id: roomId })
}
}, [roomId])

View file

@ -158,10 +158,11 @@ const state = createState({
states: {
loading: {
on: {
MOUNTED: {
do: ['resetHistory', 'restoredPreviousDocument'],
to: 'ready',
},
MOUNTED: [
'resetHistory',
{ unless: 'hasRoomId', do: 'restoredPreviousDocument' },
{ to: 'ready' },
],
},
},
ready: {
@ -1124,6 +1125,9 @@ const state = createState({
},
},
conditions: {
hasRoomId(data, payload: { roomId?: string }) {
return payload?.roomId !== undefined
},
isSimulating() {
return logger.isSimulating
},