Skip to content

Commit

Permalink
[DDW-787] Fix closing discreet mode popover on staking page
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-barros committed Nov 25, 2021
1 parent b3f9b59 commit c17d8bb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Expand Up @@ -4,23 +4,32 @@ import { observer } from 'mobx-react';
import React, { useEffect, useState } from 'react';
import type { ElementRef } from 'react';
import { AutoSizer, List, WindowScroller } from 'react-virtualized';
import { hideAll } from 'tippy.js';
import { Instance } from 'tippy.js';
import LoadingSpinner from '../../widgets/LoadingSpinner';
import styles from './StakePoolsList.scss';
import StakePool from '../../../domains/StakePool';
import { ThumbPool } from '../widgets/ThumbPool';

type TippyElement = Element & {
_tippy: Instance,
};

// Maximum number of stake pools for which we do not need to use the preloading
const PRELOADER_THRESHOLD = 100;
const POOL_THUMB_SIZE = 80;
const POOL_THUMB_GRID_GAP = 10;

/**
* Utility function to programmatically hide all pop overs
* Utility function to programmatically hide the active pop over
* This is used to hide the pool tooltips on scrolling the list
*/
function hideAllPopOvers() {
hideAll();
function hidePoolPopOver() {
const popOver: TippyElement | null = (document.querySelector('.PoolPopOver')
?.parentElement: any);

if (popOver) {
popOver?._tippy.hide();
}
}

/**
Expand Down Expand Up @@ -57,12 +66,12 @@ export const StakePoolsList = observer((props: StakePoolsListProps) => {
? props.scrollElementRef.current
: null;
if (scrollContainer !== null) {
scrollContainer.addEventListener('scroll', hideAllPopOvers, true);
scrollContainer.addEventListener('scroll', hidePoolPopOver, true);
}
setTimeout(() => setIsLoading(false));
return () => {
if (scrollContainer !== null) {
scrollContainer.removeEventListener('scroll', hideAllPopOvers);
scrollContainer.removeEventListener('scroll', hidePoolPopOver);
}
};
});
Expand Down
Expand Up @@ -55,6 +55,7 @@ export function PoolPopOver(props: {
{isHovered ? ( // Init the pop over only when the target is hovered
<PopOver
interactive
className="PoolPopOver"
delay={props.openWithDelay ? STAKE_POOL_TOOLTIP_HOVER_WAIT : 0}
duration={0}
appendTo={document.body}
Expand Down

0 comments on commit c17d8bb

Please sign in to comment.