Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

close menu after confirming avatar #9090

Merged
merged 5 commits into from
Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ All portions of the code written by the Ethereal Engine team are Copyright © 20
Ethereal Engine. All Rights Reserved.
*/

import React, { useRef } from 'react'
import React, { useEffect, useRef } from 'react'
import { useTranslation } from 'react-i18next'

import Avatar from '@etherealengine/client-core/src/common/components/Avatar'
Expand All @@ -44,8 +44,10 @@ import IconButton from '@etherealengine/ui/src/primitives/mui/IconButton'
import { EntityUUID } from '@etherealengine/common/src/interfaces/EntityUUID'
import { AvatarState } from '@etherealengine/engine/src/avatar/state/AvatarNetworkState'
import { useFind } from '@etherealengine/engine/src/common/functions/FeathersHooks'
import { EngineState } from '@etherealengine/engine/src/ecs/classes/EngineState'
import { avatarPath } from '@etherealengine/engine/src/schemas/user/avatar.schema'
import { debounce } from 'lodash'
import { LoadingCircle } from '../../../../components/LoadingCircle'
import { UserMenus } from '../../../UserUISystem'
import { AuthState } from '../../../services/AuthService'
import { PopupMenuServices } from '../PopupMenuService'
Expand All @@ -58,6 +60,8 @@ const AvatarMenu = () => {
const authState = useHookstate(getMutableState(AuthState))
const userId = authState.user?.id?.value
const userAvatarId = useHookstate(getMutableState(AvatarState)[Engine.instance.userID].avatarID as EntityUUID)
const avatarLoading = useHookstate(false)
const isUserReady = useHookstate(getMutableState(EngineState).userReady)

const page = useHookstate(0)
const selectedAvatarId = useHookstate('')
Expand All @@ -83,6 +87,7 @@ const AvatarMenu = () => {
}
}
selectedAvatarId.set('')
avatarLoading.set(true)
}

const handleSearch = async (searchString: string) => {
Expand All @@ -94,22 +99,33 @@ const AvatarMenu = () => {
searchTimeoutCancelRef.current = debounce(() => search.query.set(searchString), 1000).cancel
}

useEffect(() => {
if (avatarLoading.value && isUserReady.value) {
avatarLoading.set(false)
PopupMenuServices.showPopupMenu()
}
}, [isUserReady, avatarLoading])

return (
<Menu
open
showBackButton
actions={
<Box display="flex" width="100%">
<Button
disabled={!currentAvatar || currentAvatar.id === userAvatarId.value}
startIcon={<Icon type="Check" />}
size="medium"
type="gradientRounded"
title={t('user:avatar.confirm')}
onClick={handleConfirmAvatar}
>
{t('user:avatar.confirm')}
</Button>
{avatarLoading.value ? (
<LoadingCircle />
) : (
<Button
disabled={!currentAvatar || currentAvatar.id === userAvatarId.value}
startIcon={<Icon type="Check" />}
size="medium"
type="gradientRounded"
title={t('user:avatar.confirm')}
onClick={handleConfirmAvatar}
>
{t('user:avatar.confirm')}
</Button>
)}
</Box>
}
title={t('user:avatar.titleSelectAvatar')}
Expand Down
Loading