2021-06-21 21:35:28 +00:00
|
|
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
2021-06-17 10:43:55 +00:00
|
|
|
import { useEffect } from 'react'
|
|
|
|
import state from 'state'
|
2021-07-02 12:04:45 +00:00
|
|
|
import coopState from 'state/coop/coop-state'
|
2021-05-16 07:09:46 +00:00
|
|
|
|
2021-07-07 09:50:12 +00:00
|
|
|
export default function useLoadOnMount(roomId?: string) {
|
2021-05-16 07:09:46 +00:00
|
|
|
useEffect(() => {
|
2021-07-04 18:45:07 +00:00
|
|
|
if ('fonts' in document) {
|
|
|
|
const fonts = (document as any).fonts
|
|
|
|
fonts.load('12px Verveine Regular', 'Fonts are loaded!').then(() => {
|
2021-07-07 09:50:12 +00:00
|
|
|
state.send('MOUNTED', { roomId })
|
2021-06-17 10:43:55 +00:00
|
|
|
|
2021-07-07 12:46:46 +00:00
|
|
|
// if (roomId !== undefined) {
|
|
|
|
// state.send('RT_LOADED_ROOM', { id: roomId })
|
|
|
|
// coopState.send('JOINED_ROOM', { id: roomId })
|
|
|
|
// }
|
2021-07-04 18:45:07 +00:00
|
|
|
})
|
|
|
|
} else {
|
|
|
|
setTimeout(() => state.send('MOUNTED'), 1000)
|
|
|
|
}
|
2021-06-17 10:43:55 +00:00
|
|
|
|
2021-05-17 21:27:18 +00:00
|
|
|
return () => {
|
2021-07-07 09:50:12 +00:00
|
|
|
state.send('UNMOUNTED', { roomId })
|
2021-07-02 12:04:45 +00:00
|
|
|
coopState.send('LEFT_ROOM', { id: roomId })
|
2021-05-17 21:27:18 +00:00
|
|
|
}
|
2021-06-28 20:45:06 +00:00
|
|
|
}, [roomId])
|
2021-05-16 07:09:46 +00:00
|
|
|
}
|