@@ -11,12 +11,11 @@ interface ProfileInfoTooltipProps {
11
11
className ?: string ;
12
12
}
13
13
14
- // Profile ID validation: only allow alphanumeric, hyphens, underscores, max 64 chars
15
14
function isValidProfileId ( profileId : string ) : boolean {
16
15
return typeof profileId === 'string' &&
17
16
profileId . length > 0 &&
18
17
profileId . length <= 64 &&
19
- / ^ [ a - z A - Z 0 - 9 _ - ] + $ / . test ( profileId ) ;
18
+ / ^ [ a - z A - Z 0 - 9 _ \- ] + $ / . test ( profileId ) ;
20
19
}
21
20
22
21
@@ -25,7 +24,7 @@ function getPortFromAdvanced(profile: LocalLoginProfile): string | null {
25
24
const defaultPortItem = databaseTypeDropdownItems . find ( item => item . id === dbType ) ;
26
25
27
26
if ( ! defaultPortItem ?. extra ?. Port ) {
28
- return null ; // No default port found, hide this info
27
+ return null ;
29
28
}
30
29
31
30
const defaultPort = defaultPortItem . extra . Port ;
@@ -40,27 +39,26 @@ function getPortFromAdvanced(profile: LocalLoginProfile): string | null {
40
39
41
40
function getLastAccessedTime ( profileId : string ) : string | null {
42
41
if ( ! isValidProfileId ( profileId ) ) {
43
- return null ; // Invalid profile ID, hide this info
42
+ return null ;
44
43
}
45
44
46
45
try {
47
46
const lastAccessed = localStorage . getItem ( `whodb_profile_last_accessed_${ profileId } ` ) ;
48
47
if ( lastAccessed ) {
49
48
const date = new Date ( lastAccessed ) ;
50
49
if ( isNaN ( date . getTime ( ) ) ) {
51
- return null ; // Invalid date, hide this info
50
+ return null ;
52
51
}
53
52
const timeZone = Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ;
54
53
const formattedTimeZone = timeZone . replace ( / _ / g, ' ' ) . split ( '/' ) . join ( ' / ' ) ;
55
54
return `${ date . toLocaleDateString ( ) } ${ date . toLocaleTimeString ( [ ] , { hour : '2-digit' , minute : '2-digit' } ) } (${ formattedTimeZone } )` ;
56
55
}
57
56
} catch ( error ) {
58
- // Silently fail - return null to hide this info
57
+ return null ;
59
58
}
60
59
return null ;
61
60
}
62
61
63
- // Portal container reuse - create once and reuse
64
62
let tooltipPortalContainer : HTMLDivElement | null = null ;
65
63
66
64
function getTooltipPortalContainer ( ) : HTMLDivElement {
@@ -80,30 +78,26 @@ export const ProfileInfoTooltip: FC<ProfileInfoTooltipProps> = ({ profile, class
80
78
const port = getPortFromAdvanced ( profile ) ;
81
79
const lastAccessed = getLastAccessedTime ( profile . Id ) ;
82
80
83
- // If no information is available, don't render the component
84
81
const hasInfo = port !== null || lastAccessed !== null ;
85
82
if ( ! hasInfo ) {
86
83
return null ;
87
84
}
88
85
89
- // Show tooltip to the right of the icon
90
86
const showTooltip = useCallback ( ( ) => {
91
87
if ( btnRef . current ) {
92
88
const rect = btnRef . current . getBoundingClientRect ( ) ;
93
89
setTooltipPos ( {
94
90
top : rect . top + rect . height / 2 ,
95
- left : rect . right + 12 , // 12px gap to the right
91
+ left : rect . right + 12 ,
96
92
} ) ;
97
93
}
98
94
setIsVisible ( true ) ;
99
95
} , [ ] ) ;
100
96
101
- // Hide tooltip
102
97
const hideTooltip = useCallback ( ( ) => {
103
98
setIsVisible ( false ) ;
104
99
} , [ ] ) ;
105
100
106
- // Memoized event handlers to prevent recreation
107
101
const handleClickAway = useCallback ( ( event : MouseEvent ) => {
108
102
if (
109
103
btnRef . current &&
@@ -117,7 +111,6 @@ export const ProfileInfoTooltip: FC<ProfileInfoTooltipProps> = ({ profile, class
117
111
if ( event . key === "Escape" ) setIsVisible ( false ) ;
118
112
} , [ ] ) ;
119
113
120
- // Optimized event listeners - only add when visible, use stable handlers
121
114
useEffect ( ( ) => {
122
115
if ( ! isVisible ) return ;
123
116
@@ -130,7 +123,6 @@ export const ProfileInfoTooltip: FC<ProfileInfoTooltipProps> = ({ profile, class
130
123
} ;
131
124
} , [ isVisible , handleClickAway , handleKeyDown ] ) ;
132
125
133
- // Memoize portal container to prevent recreation
134
126
const portalContainer = useMemo ( ( ) => getTooltipPortalContainer ( ) , [ ] ) ;
135
127
136
128
const tooltip = isVisible && tooltipPos
@@ -193,15 +185,14 @@ export const ProfileInfoTooltip: FC<ProfileInfoTooltipProps> = ({ profile, class
193
185
) ;
194
186
} ;
195
187
196
- // Utility function to update last accessed time with validation
197
188
export function updateProfileLastAccessed ( profileId : string ) : void {
198
189
if ( ! isValidProfileId ( profileId ) ) {
199
- return ; // Silently fail for invalid profile IDs
190
+ return ;
200
191
}
201
192
202
193
try {
203
194
localStorage . setItem ( `whodb_profile_last_accessed_${ profileId } ` , new Date ( ) . toISOString ( ) ) ;
204
195
} catch ( error ) {
205
- // Silently fail - localStorage may be full or disabled
196
+
206
197
}
207
198
}
0 commit comments