Skip to content
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
@@ -1,6 +1,6 @@
import { Dispatch, SetStateAction, useContext, useEffect, useState } from 'react'
import { Dispatch, SetStateAction, useEffect, useState } from 'react'

import { profileContext, ProfileContextData, profileGetPublicAsync, UserProfile } from '../../../../lib'
import { profileGetPublicAsync, UserProfile } from '../../../../lib'

export interface UseGetUserProfileData {
isOwnProfile: boolean
Expand All @@ -9,8 +9,6 @@ export interface UseGetUserProfileData {
}

export function useGetUserProfile(memberHandle?: string): UseGetUserProfileData {
const profileData: ProfileContextData = useContext(profileContext)

const [profile, setProfile]: [
UserProfile | undefined,
Dispatch<SetStateAction<UserProfile | undefined>>
Expand All @@ -19,21 +17,14 @@ export function useGetUserProfile(memberHandle?: string): UseGetUserProfileData
const [profileReady, setProfileReady]: [boolean, Dispatch<SetStateAction<boolean>>] = useState<boolean>(false)

useEffect(() => {
if (!profileData?.initialized) {
return
}

if (profileData.profile) {
setProfile(profileData.profile)
setProfileReady(true)
} else if (memberHandle) {
if (memberHandle) {
profileGetPublicAsync(memberHandle)
.then(userProfile => {
setProfile(userProfile)
setProfileReady(true)
})
}
}, [memberHandle, profileData?.initialized, profileData.profile, setProfileReady])
}, [memberHandle, setProfileReady])

return {
isOwnProfile: !!profile?.email,
Expand Down