48 lines
2.4 KiB
TypeScript
48 lines
2.4 KiB
TypeScript
// Metro module 15558 (f15559).
|
|
import { useRef, useEffect } from "react";
|
|
import { SearchTabs } from "../../SearchConstants";
|
|
import Tracking from "../tracking/Tracking";
|
|
export function useAutoTrackSearchTabCountsViewedAnalytics({ searchContext, visibleTabCounts, visibleTabs }) {
|
|
const ref = useRef(visibleTabs);
|
|
useEffect(() => {
|
|
ref.current = visibleTabs;
|
|
}, [visibleTabs]);
|
|
useEffect(() => {
|
|
if (visibleTabCounts != null) {
|
|
const searchResultTotalCount = Object.keys(visibleTabCounts).reduce((acc, item) => {
|
|
let r4 = visibleTabCounts == null ? null : ref.current.includes(item) ? visibleTabCounts[item] : null;
|
|
if (r4 == null) {
|
|
r4 = 0;
|
|
}
|
|
return acc + r4;
|
|
}, 0);
|
|
if (searchResultTotalCount > 0) {
|
|
const MEMBERS = SearchTabs.MEMBERS;
|
|
const numMemberTabReturnedResults = visibleTabCounts == null ? null : ref.current.includes(MEMBERS) ? visibleTabCounts[MEMBERS] : null;
|
|
const GUILD_CHANNELS = SearchTabs.GUILD_CHANNELS;
|
|
const numChannelTabReturnedResults = visibleTabCounts == null ? null : ref.current.includes(GUILD_CHANNELS) ? visibleTabCounts[GUILD_CHANNELS] : null;
|
|
const PEOPLE = SearchTabs.PEOPLE;
|
|
const numPeopleTabReturnedResults = visibleTabCounts == null ? null : ref.current.includes(PEOPLE) ? visibleTabCounts[PEOPLE] : null;
|
|
const MESSAGES = SearchTabs.MESSAGES;
|
|
const numMessageTabReturnedResults = visibleTabCounts == null ? null : ref.current.includes(MESSAGES) ? visibleTabCounts[MESSAGES] : null;
|
|
const MEDIA = SearchTabs.MEDIA;
|
|
const numMediaTabReturnedResults = visibleTabCounts == null ? null : ref.current.includes(MEDIA) ? visibleTabCounts[MEDIA] : null;
|
|
const FILES = SearchTabs.FILES;
|
|
const numFileTabReturnedResults = visibleTabCounts == null ? null : ref.current.includes(FILES) ? visibleTabCounts[FILES] : null;
|
|
const LINKS = SearchTabs.LINKS;
|
|
Tracking.trackSearchResultReturned({
|
|
searchContext,
|
|
searchResultTotalCount,
|
|
numMemberTabReturnedResults,
|
|
numChannelTabReturnedResults,
|
|
numPeopleTabReturnedResults,
|
|
numMessageTabReturnedResults,
|
|
numMediaTabReturnedResults,
|
|
numFileTabReturnedResults,
|
|
numLinkTabReturnedResults: visibleTabCounts == null ? null : ref.current.includes(LINKS) ? visibleTabCounts[LINKS] : null
|
|
});
|
|
}
|
|
}
|
|
}, [searchContext, visibleTabCounts]);
|
|
}
|