@@ -23,7 +23,7 @@ All portions of the code written by the Ethereal Engine team are Copyright © 20
23
23
Ethereal Engine. All Rights Reserved.
24
24
*/
25
25
26
- import React , { useRef } from 'react'
26
+ import React , { useEffect , useRef } from 'react'
27
27
import { useTranslation } from 'react-i18next'
28
28
29
29
import Avatar from '@etherealengine/client-core/src/common/components/Avatar'
@@ -44,8 +44,10 @@ import IconButton from '@etherealengine/ui/src/primitives/mui/IconButton'
44
44
import { EntityUUID } from '@etherealengine/common/src/interfaces/EntityUUID'
45
45
import { AvatarState } from '@etherealengine/engine/src/avatar/state/AvatarNetworkState'
46
46
import { useFind } from '@etherealengine/engine/src/common/functions/FeathersHooks'
47
+ import { EngineState } from '@etherealengine/engine/src/ecs/classes/EngineState'
47
48
import { avatarPath } from '@etherealengine/engine/src/schemas/user/avatar.schema'
48
49
import { debounce } from 'lodash'
50
+ import { LoadingCircle } from '../../../../components/LoadingCircle'
49
51
import { UserMenus } from '../../../UserUISystem'
50
52
import { AuthState } from '../../../services/AuthService'
51
53
import { PopupMenuServices } from '../PopupMenuService'
@@ -58,6 +60,8 @@ const AvatarMenu = () => {
58
60
const authState = useHookstate ( getMutableState ( AuthState ) )
59
61
const userId = authState . user ?. id ?. value
60
62
const userAvatarId = useHookstate ( getMutableState ( AvatarState ) [ Engine . instance . userID ] . avatarID as EntityUUID )
63
+ const avatarLoading = useHookstate ( false )
64
+ const isUserReady = useHookstate ( getMutableState ( EngineState ) . userReady )
61
65
62
66
const page = useHookstate ( 0 )
63
67
const selectedAvatarId = useHookstate ( '' )
@@ -83,6 +87,7 @@ const AvatarMenu = () => {
83
87
}
84
88
}
85
89
selectedAvatarId . set ( '' )
90
+ avatarLoading . set ( true )
86
91
}
87
92
88
93
const handleSearch = async ( searchString : string ) => {
@@ -94,22 +99,33 @@ const AvatarMenu = () => {
94
99
searchTimeoutCancelRef . current = debounce ( ( ) => search . query . set ( searchString ) , 1000 ) . cancel
95
100
}
96
101
102
+ useEffect ( ( ) => {
103
+ if ( avatarLoading . value && isUserReady . value ) {
104
+ avatarLoading . set ( false )
105
+ PopupMenuServices . showPopupMenu ( )
106
+ }
107
+ } , [ isUserReady , avatarLoading ] )
108
+
97
109
return (
98
110
< Menu
99
111
open
100
112
showBackButton
101
113
actions = {
102
114
< Box display = "flex" width = "100%" >
103
- < Button
104
- disabled = { ! currentAvatar || currentAvatar . id === userAvatarId . value }
105
- startIcon = { < Icon type = "Check" /> }
106
- size = "medium"
107
- type = "gradientRounded"
108
- title = { t ( 'user:avatar.confirm' ) }
109
- onClick = { handleConfirmAvatar }
110
- >
111
- { t ( 'user:avatar.confirm' ) }
112
- </ Button >
115
+ { avatarLoading . value ? (
116
+ < LoadingCircle />
117
+ ) : (
118
+ < Button
119
+ disabled = { ! currentAvatar || currentAvatar . id === userAvatarId . value }
120
+ startIcon = { < Icon type = "Check" /> }
121
+ size = "medium"
122
+ type = "gradientRounded"
123
+ title = { t ( 'user:avatar.confirm' ) }
124
+ onClick = { handleConfirmAvatar }
125
+ >
126
+ { t ( 'user:avatar.confirm' ) }
127
+ </ Button >
128
+ ) }
113
129
</ Box >
114
130
}
115
131
title = { t ( 'user:avatar.titleSelectAvatar' ) }
0 commit comments