Files
discord-decomp/modules/collectibles/profile_frames/hooks/useMaybeTrackProfileFrameViewed.tsx
T
2026-11-01 12:12:55 +02:00

45 lines
1.7 KiB
TypeScript

// Metro module 8366 (f8367).
import { useEffect, useRef } from "react";
import CollectiblesCategoryStore from "../../CollectiblesCategoryStore";
import { useStateFromStores } from "../../../../_bundle/defaultAreStatesEqual";
import { maybeTrackUserProfileUiViewed } from "../../../user_profile/UserProfileAnalyticsUtils";
export default function useMaybeTrackProfileFrameViewed({ skuId, openedAt, context, analyticsLocations }) {
let ref, ref2, ref3, ref4;
ref = void 0;
ref2 = void 0;
ref3 = void 0;
ref4 = void 0;
const stateFromStores = useStateFromStores([CollectiblesCategoryStore], () => CollectiblesCategoryStore.getProductFetch(skuId));
ref = useRef(void 0);
ref2 = useRef(void 0);
ref3 = useRef(void 0);
ref4 = useRef(false);
useEffect(() => {
if (skuId != null && openedAt != null) {
if (!(ref2.current === skuId && ref3.current === openedAt)) {
ref2.current = skuId;
ref3.current = openedAt;
ref4.current = false;
ref.current = void 0;
}
const r9 = Date.now();
if (ref.current == null) {
ref.current = r9 - openedAt;
}
if (!(stateFromStores?.state !== "success" || ref4.current)) {
ref4.current = true;
maybeTrackUserProfileUiViewed({
profileUi: "PROFILE_FRAME",
timeToInteractiveMs: ref.current,
timeToLoadMs: r9 - openedAt,
timeToFetchMs: stateFromStores.startedAt != null ? stateFromStores.endedAt != null ? stateFromStores.endedAt - stateFromStores.startedAt : void 0 : void 0,
viewStartedAt: openedAt,
fetchStartedAt: stateFromStores.startedAt,
analyticsLocations,
...context
});
}
}
}, [skuId, openedAt, stateFromStores]);
};