78 lines
3.2 KiB
TypeScript
78 lines
3.2 KiB
TypeScript
// Metro module 11916 (f11917).
|
|
import { useRef, useCallback, useEffect } from "react";
|
|
import CollectiblesCategoryStore from "../CollectiblesCategoryStore";
|
|
import { AnalyticEvents } from "../../../Constants";
|
|
import { useCollectiblesAnalyticsContext } from "../CollectiblesAnalyticsContext";
|
|
import { useStateFromStores } from "../../../_bundle/Module589";
|
|
import { useCurrentUser } from "./useCurrentUser";
|
|
import PremiumUtils from "../../../utils/PremiumUtils";
|
|
import { getPriceForCollectiblesProduct, getStrikeThroughPriceAmountForCollectiblesProduct } from "../CollectiblesUtils";
|
|
import AnalyticsUtils from "../../../utils/AnalyticsUtils";
|
|
export function useTrackProductCardImpression(a0, a1) {
|
|
let canUseShopDiscounts, ref, callback;
|
|
const sku_id = a0;
|
|
const page_type = a1;
|
|
let r9 = arguments[2];
|
|
if (r9 === void 0) {
|
|
r9 = "product";
|
|
}
|
|
const type = r9;
|
|
canUseShopDiscounts = void 0;
|
|
ref = void 0;
|
|
callback = void 0;
|
|
const collectiblesAnalyticsContext = useCollectiblesAnalyticsContext();
|
|
const stateFromStores = useStateFromStores([CollectiblesCategoryStore], () => CollectiblesCategoryStore.getProduct(sku_id));
|
|
canUseShopDiscounts = PremiumUtils.canUseShopDiscounts(useCurrentUser());
|
|
ref = useRef(null);
|
|
const r35 = [collectiblesAnalyticsContext?.sessionId, collectiblesAnalyticsContext?.categoryPosition, collectiblesAnalyticsContext?.pageCategory, collectiblesAnalyticsContext?.pageSection, , , , , , ,];
|
|
const tilePosition = collectiblesAnalyticsContext?.tilePosition;
|
|
const r44 = () => {
|
|
const r11 = stateFromStores != null ? getPriceForCollectiblesProduct(stateFromStores, canUseShopDiscounts, true) : null;
|
|
const display_price_strikethrough = stateFromStores != null ? getStrikeThroughPriceAmountForCollectiblesProduct(stateFromStores, canUseShopDiscounts, true) : void 0;
|
|
const COLLECTIBLES_TILE_IMPRESSION = AnalyticEvents.COLLECTIBLES_TILE_IMPRESSION;
|
|
AnalyticsUtils.track(COLLECTIBLES_TILE_IMPRESSION, {
|
|
collectibles_shop_session_id: collectiblesAnalyticsContext?.sessionId,
|
|
sku_id,
|
|
display_price: r11?.amount,
|
|
display_price_currency: r11 == null ? void 0 : r11.currency.toString(),
|
|
display_price_strikethrough,
|
|
position: collectiblesAnalyticsContext?.tilePosition,
|
|
page_type,
|
|
page_category: collectiblesAnalyticsContext?.pageCategory,
|
|
page_section: collectiblesAnalyticsContext?.pageSection,
|
|
type,
|
|
category_position: collectiblesAnalyticsContext?.categoryPosition
|
|
});
|
|
};
|
|
r35[4] = tilePosition;
|
|
r35[5] = canUseShopDiscounts;
|
|
r35[6] = a1;
|
|
r35[7] = stateFromStores;
|
|
r35[8] = a0;
|
|
r35[9] = type;
|
|
callback = useCallback(r44, r35);
|
|
const callback2 = useCallback((a0) => {
|
|
const current = ref.current;
|
|
if (a0) {
|
|
if (current === null) {
|
|
ref.current = setTimeout(() => {
|
|
callback();
|
|
ref.current = null;
|
|
}, 1000);
|
|
}
|
|
} else if (current !== null) {
|
|
clearTimeout(ref.current);
|
|
ref.current = null;
|
|
}
|
|
}, [callback]);
|
|
useEffect(() => () => {
|
|
if (ref.current !== null) {
|
|
clearTimeout(ref.current);
|
|
ref.current = null;
|
|
}
|
|
}, [a0]);
|
|
return {
|
|
handleCardVisibilityChange: callback2
|
|
};
|
|
}
|