Skip to content

Commit

Permalink
wait a sec before showing card (#3516)
Browse files Browse the repository at this point in the history
  • Loading branch information
haileyok authored Apr 12, 2024
1 parent cefa0a5 commit 7d01ff9
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/components/ProfileHoverCard/index.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,25 @@ export function ProfileHoverCardInner(props: ProfileHoverCardProps) {
const targetHovered = React.useRef(false)
const cardHovered = React.useRef(false)
const targetClicked = React.useRef(false)
const showTimeout = React.useRef<NodeJS.Timeout>()

const onPointerEnterTarget = React.useCallback(() => {
targetHovered.current = true
showTimeout.current = setTimeout(async () => {
targetHovered.current = true

if (prefetchedProfile.current) {
// if we're navigating
if (targetClicked.current) return
setHovered(true)
} else {
await prefetchProfileQuery(props.did)

if (prefetchedProfile.current) {
// if we're navigating
if (targetClicked.current) return
setHovered(true)
} else {
prefetchProfileQuery(props.did).then(() => {
if (targetHovered.current) {
setHovered(true)
}
prefetchedProfile.current = true
})
}
}
}, 350)
}, [props.did, prefetchProfileQuery])
const onPointerEnterCard = React.useCallback(() => {
cardHovered.current = true
Expand All @@ -86,6 +89,7 @@ export function ProfileHoverCardInner(props: ProfileHoverCardProps) {
setHovered(true)
}, [])
const onPointerLeaveTarget = React.useCallback(() => {
clearTimeout(showTimeout.current)
targetHovered.current = false
setTimeout(() => {
if (cardHovered.current) return
Expand Down

0 comments on commit 7d01ff9

Please sign in to comment.