125 lines
4.2 KiB
TypeScript
125 lines
4.2 KiB
TypeScript
// Metro module 8107 (f8108).
|
|
import { createContext, useRef, useEffect, useContext, useMemo, useCallback } from "react";
|
|
import useAnalyticsLocations from "../app_analytics/useAnalyticsLocations";
|
|
import * as _UserProfileAnalyticsUtils from "./UserProfileAnalyticsUtils";
|
|
import { maybeTrackUserProfileUiViewed } from "./UserProfileAnalyticsUtils";
|
|
import { v4 } from "../../_bundle/Module514";
|
|
const context = createContext(null);
|
|
export const UserProfileAnalyticsProvider = ({ value, children, openedAt, fetchStartedAt, fetchEndedAt, isLoaded = false }) => {
|
|
let c16252_3 = isLoaded;
|
|
const analyticsLocations2 = useAnalyticsLocations().analyticsLocations;
|
|
const ref = useRef(void 0);
|
|
const ref3 = useRef(openedAt);
|
|
if (ref3.current !== openedAt) {
|
|
ref3.current = openedAt;
|
|
ref.current = void 0;
|
|
}
|
|
const current = {
|
|
analyticsLocations: analyticsLocations2,
|
|
value
|
|
};
|
|
const ref2 = useRef(current);
|
|
useEffect(() => {
|
|
ref2.current = current;
|
|
});
|
|
useEffect(() => {
|
|
const r10 = Date.now();
|
|
if (ref.current == null && openedAt != null) {
|
|
ref.current = r10 - openedAt;
|
|
}
|
|
if (c16252_3) {
|
|
const current2 = ref2.current;
|
|
const { analyticsLocations: analyticsLocations2, value } = current2;
|
|
_UserProfileAnalyticsUtils.trackUserProfileAction({
|
|
action: "VIEW",
|
|
analyticsLocations: analyticsLocations2,
|
|
...value
|
|
});
|
|
maybeTrackUserProfileUiViewed({
|
|
profileUi: "USER_PROFILE",
|
|
timeToInteractiveMs: ref.current,
|
|
timeToLoadMs: openedAt != null ? r10 - openedAt : void 0,
|
|
timeToFetchMs: fetchStartedAt != null ? fetchEndedAt != null ? fetchEndedAt - fetchStartedAt : void 0 : void 0,
|
|
viewStartedAt: openedAt,
|
|
fetchStartedAt,
|
|
analyticsLocations: analyticsLocations2,
|
|
...value
|
|
});
|
|
}
|
|
}, [isLoaded]);
|
|
return <context.Provider value={value}>{children}</context.Provider>;
|
|
};
|
|
export function useCreateUserProfileAnalyticsContext({ layout, userId, guildId, channelId, messageId, roleId, sourceSessionId, showGuildProfile: showGuildProfile2 = true }) {
|
|
const showGuildProfile = showGuildProfile2;
|
|
const sessionId = useContext(context)?.sessionId;
|
|
return useMemo(() => {
|
|
const r1 = {
|
|
sessionId: v4(),
|
|
sourceSessionId: null,
|
|
layout: null,
|
|
userId: null,
|
|
guildId: null,
|
|
channelId: null,
|
|
messageId: null,
|
|
roleId: null,
|
|
showGuildProfile: null
|
|
};
|
|
let sourceSessionId2 = sourceSessionId;
|
|
if (sourceSessionId == null) {
|
|
sourceSessionId2 = sessionId;
|
|
}
|
|
r1.sourceSessionId = sourceSessionId2;
|
|
r1.layout = layout;
|
|
r1.userId = userId;
|
|
r1.guildId = guildId;
|
|
r1.channelId = channelId;
|
|
r1.messageId = messageId;
|
|
r1.roleId = roleId;
|
|
r1.showGuildProfile = showGuildProfile;
|
|
return r1;
|
|
}, [sessionId, layout, userId, guildId, channelId, messageId, roleId, sourceSessionId, showGuildProfile]);
|
|
}
|
|
export function useUserProfileAnalyticsContext() {
|
|
const context2 = useContext(context);
|
|
const analyticsLocations = useAnalyticsLocations().analyticsLocations;
|
|
return {
|
|
context: context2,
|
|
trackUserProfileAction: useCallback((a0) => {
|
|
if (context2 != null) {
|
|
_UserProfileAnalyticsUtils.trackUserProfileAction({
|
|
analyticsLocations,
|
|
...context2,
|
|
...a0
|
|
});
|
|
}
|
|
}, [context2, analyticsLocations]),
|
|
trackUserProfileEditAction: useCallback((a0) => {
|
|
if (context2 != null) {
|
|
_UserProfileAnalyticsUtils.trackUserProfileEditAction({
|
|
analyticsLocations,
|
|
...context2,
|
|
...a0
|
|
});
|
|
}
|
|
}, [context2, analyticsLocations]),
|
|
trackUserProfileEditSaved: useCallback((a0) => {
|
|
if (context2 != null) {
|
|
_UserProfileAnalyticsUtils.trackUserProfileEditSaved({
|
|
analyticsLocations,
|
|
...context2,
|
|
...a0
|
|
});
|
|
}
|
|
}, [context2, analyticsLocations]),
|
|
trackUserProfileWishlistAction: useCallback((a0) => {
|
|
if (context2 != null) {
|
|
_UserProfileAnalyticsUtils.trackUserProfileWishlistAction({
|
|
analyticsLocations,
|
|
...context2,
|
|
...a0
|
|
});
|
|
}
|
|
}, [context2, analyticsLocations])
|
|
};
|
|
}
|