@@ -2,45 +2,73 @@ import { Dispatch, FC, SetStateAction, useContext, useState } from 'react'
22
33import {
44 Avatar ,
5+ ComponentVisible ,
56 IconOutline ,
67 logInfo ,
78 profileContext ,
89 ProfileContextData ,
10+ useHideClickOutside ,
911} from '../../../../../lib'
1012
1113import { ProfilePanel } from './profile-panel'
1214import styles from './ProfileLoggedIn.module.scss'
1315
14- const ProfileLoggedIn : FC < { } > = ( ) => {
16+ interface ProfileLoggedInProps {
17+ settingsTitle : string
18+ }
19+
20+ const ProfileLoggedIn : FC < ProfileLoggedInProps > = ( props : ProfileLoggedInProps ) => {
1521
1622 const { profile } : ProfileContextData = useContext ( profileContext )
1723 const [ profilePanelOpen , setProfilePanelOpen ] : [ boolean , Dispatch < SetStateAction < boolean > > ] = useState < boolean > ( false )
1824
25+ const {
26+ isComponentVisible,
27+ ref,
28+ setIsComponentVisible,
29+ } : ComponentVisible = useHideClickOutside ( false )
30+
1931 if ( ! profile ) {
2032 logInfo ( 'tried to render the logged in profile w/out a profile' )
2133 return < > </ >
2234 }
2335
2436 function toggleProfilePanel ( ) : void {
25- setProfilePanelOpen ( ! profilePanelOpen )
37+ const toggleTo : boolean = ! profilePanelOpen
38+ setProfilePanelOpen ( toggleTo )
39+ setIsComponentVisible ( toggleTo )
40+ }
41+
42+ if ( ! isComponentVisible && profilePanelOpen ) {
43+ setProfilePanelOpen ( isComponentVisible )
2644 }
2745
2846 return (
2947 < >
30- < div className = { styles [ 'profile-avatar' ] } onClick = { ( ) => toggleProfilePanel ( ) } >
48+ < div
49+ className = { styles [ 'profile-avatar' ] }
50+ onClick = { toggleProfilePanel }
51+ >
3152 < Avatar
3253 firstName = { profile . firstName }
3354 lastName = { profile . lastName }
3455 handle = { profile . handle }
3556 photoUrl = { profile . photoURL }
57+ size = 'sm'
3658 />
3759 { profilePanelOpen && (
3860 < div className = { styles . overlay } >
3961 < IconOutline . XIcon />
4062 </ div >
4163 ) }
4264 </ div >
43- { profilePanelOpen && < ProfilePanel toggleProfilePanel = { toggleProfilePanel } /> }
65+ { profilePanelOpen && (
66+ < ProfilePanel
67+ refObject = { ref }
68+ settingsTitle = { props . settingsTitle }
69+ toggleProfilePanel = { toggleProfilePanel }
70+ />
71+ ) }
4472 </ >
4573 )
4674}
0 commit comments