Skip to content

Commit

Permalink
release tooltip event listener adding func (#5019)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Kane <ben@voxel51.com>
  • Loading branch information
sashankaryal and benjaminpkane authored Oct 31, 2024
1 parent 779fb83 commit 35f8f61
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions app/packages/core/src/components/Modal/ModalSamplePlugin.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ErrorBoundary } from "@fiftyone/components";
import * as fos from "@fiftyone/state";
import React, { Suspense, useEffect } from "react";
import React, { Suspense, useCallback, useEffect, useMemo } from "react";
import { useRecoilCallback, useRecoilValue, useSetRecoilState } from "recoil";
import styled from "styled-components";
import Group from "./Group";
Expand Down Expand Up @@ -48,18 +48,30 @@ export const ModalSample = React.memo(() => {

const { activeLookerRef, onLookerSetSubscribers } = useModalContext();

useEffect(() => {
onLookerSetSubscribers.current.push((looker) => {
const addTooltipEventListener = useMemo(() => {
return (looker: fos.Lookers) => {
looker.addEventListener("tooltip", tooltipEventHandler);
});
};
}, []);

useEffect(() => {
onLookerSetSubscribers.current.push(addTooltipEventListener);

return () => {
activeLookerRef?.current?.removeEventListener(
"tooltip",
tooltipEventHandler
);
onLookerSetSubscribers.current = onLookerSetSubscribers.current.filter(
(fn) => fn !== addTooltipEventListener
);
};
}, [activeLookerRef, onLookerSetSubscribers, tooltipEventHandler]);
}, [
activeLookerRef,
addTooltipEventListener,
onLookerSetSubscribers,
tooltipEventHandler,
]);

useEffect(() => {
// reset tooltip state when modal is closed
Expand Down

0 comments on commit 35f8f61

Please sign in to comment.