| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.SetTooltipEntrySettings = SetTooltipEntrySettings;
|
|---|
| 7 | var _react = require("react");
|
|---|
| 8 | var _hooks = require("./hooks");
|
|---|
| 9 | var _tooltipSlice = require("./tooltipSlice");
|
|---|
| 10 | var _PanoramaContext = require("../context/PanoramaContext");
|
|---|
| 11 | function SetTooltipEntrySettings(_ref) {
|
|---|
| 12 | var {
|
|---|
| 13 | tooltipEntrySettings
|
|---|
| 14 | } = _ref;
|
|---|
| 15 | var dispatch = (0, _hooks.useAppDispatch)();
|
|---|
| 16 | var isPanorama = (0, _PanoramaContext.useIsPanorama)();
|
|---|
| 17 | var prevSettingsRef = (0, _react.useRef)(null);
|
|---|
| 18 | (0, _react.useLayoutEffect)(() => {
|
|---|
| 19 | if (isPanorama) {
|
|---|
| 20 | // Panorama graphical items should never contribute to Tooltip payload.
|
|---|
| 21 | return;
|
|---|
| 22 | }
|
|---|
| 23 | if (prevSettingsRef.current === null) {
|
|---|
| 24 | dispatch((0, _tooltipSlice.addTooltipEntrySettings)(tooltipEntrySettings));
|
|---|
| 25 | } else if (prevSettingsRef.current !== tooltipEntrySettings) {
|
|---|
| 26 | dispatch((0, _tooltipSlice.replaceTooltipEntrySettings)({
|
|---|
| 27 | prev: prevSettingsRef.current,
|
|---|
| 28 | next: tooltipEntrySettings
|
|---|
| 29 | }));
|
|---|
| 30 | }
|
|---|
| 31 | prevSettingsRef.current = tooltipEntrySettings;
|
|---|
| 32 | }, [tooltipEntrySettings, dispatch, isPanorama]);
|
|---|
| 33 | (0, _react.useLayoutEffect)(() => {
|
|---|
| 34 | return () => {
|
|---|
| 35 | if (prevSettingsRef.current) {
|
|---|
| 36 | dispatch((0, _tooltipSlice.removeTooltipEntrySettings)(prevSettingsRef.current));
|
|---|
| 37 | prevSettingsRef.current = null;
|
|---|
| 38 | }
|
|---|
| 39 | };
|
|---|
| 40 | }, [dispatch]);
|
|---|
| 41 | return null;
|
|---|
| 42 | } |
|---|