Skip to content

Commit

Permalink
fix: cancel debounce
Browse files Browse the repository at this point in the history
  • Loading branch information
astandrik committed Oct 10, 2024
1 parent 9086ed1 commit 6ce9c94
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions src/components/VDisk/VDisk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,15 @@ export const VDisk = ({

const anchor = React.useRef(null);

const handleShowPopup = () => {
const debouncedHandleShowPopup = debounce(() => {
setIsPopupVisible(true);
onShowPopup?.();
};
}, DEBOUNCE_TIMEOUT);

const handleHidePopup = () => {
const debouncedHandleHidePopup = debounce(() => {
setIsPopupVisible(false);
onHidePopup?.();
};

const debouncedHandleShowPopup = debounce(handleShowPopup, DEBOUNCE_TIMEOUT);
const debouncedHandleHidePopup = debounce(handleHidePopup, DEBOUNCE_TIMEOUT);
}, DEBOUNCE_TIMEOUT);

let vDiskPath: string | undefined;

Expand Down Expand Up @@ -85,7 +82,10 @@ export const VDisk = ({
className={b()}
ref={anchor}
onMouseEnter={debouncedHandleShowPopup}
onMouseLeave={debouncedHandleHidePopup}
onMouseLeave={() => {
debouncedHandleShowPopup.cancel();
debouncedHandleHidePopup();
}}
>
<InternalLink to={vDiskPath} className={b('content')}>
<DiskStateProgressBar
Expand Down
16 changes: 8 additions & 8 deletions src/containers/Storage/PDisk/PDisk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,15 @@ export const PDisk = ({
const {NodeId, PDiskId} = data;
const pDiskIdsDefined = valueIsDefined(NodeId) && valueIsDefined(PDiskId);

const handleShowPopup = () => {
const debouncedHandleShowPopup = debounce(() => {
setIsPopupVisible(true);
onShowPopup?.();
};
}, DEBOUNCE_TIMEOUT);

const handleHidePopup = () => {
const debouncedHandleHidePopup = debounce(() => {
setIsPopupVisible(false);
onHidePopup?.();
};

const debouncedHandleShowPopup = debounce(handleShowPopup, DEBOUNCE_TIMEOUT);
const debouncedHandleHidePopup = debounce(handleHidePopup, DEBOUNCE_TIMEOUT);
}, DEBOUNCE_TIMEOUT);

const renderVDisks = () => {
if (!vDisks?.length) {
Expand Down Expand Up @@ -113,7 +110,10 @@ export const PDisk = ({
to={pDiskPath}
className={b('content')}
onMouseEnter={debouncedHandleShowPopup}
onMouseLeave={debouncedHandleHidePopup}
onMouseLeave={() => {
debouncedHandleShowPopup.cancel();
debouncedHandleHidePopup();
}}
>
<DiskStateProgressBar
diskAllocatedPercent={data.AllocatedPercent}
Expand Down

0 comments on commit 6ce9c94

Please sign in to comment.