241 lines
11 KiB
TypeScript
241 lines
11 KiB
TypeScript
// Metro module 15475 (f15476).
|
|
import * as Module19 from "react";
|
|
import { useEffect, useMemo, useCallback, useRef, useContext } from "react";
|
|
import { View } from "react-native";
|
|
import SearchMessageStore from "../../../SearchMessageStore";
|
|
import SearchQueryStore from "../../stores/SearchQueryStore";
|
|
import SearchTabsLayoutStore from "../../stores/SearchTabsLayoutStore";
|
|
import { MESSAGE_SEARCH_RESULT_TABS_SET, SEARCH_MESSAGE_TAB_SENTINEL, SearchTabs } from "../../../SearchConstants";
|
|
import { ComponentActions } from "../../../../../Constants";
|
|
import { createStyles } from "../../../../../design/components/Styles/native/createStyles";
|
|
import { debounce } from "../../../../../_bundle/Module12";
|
|
import Tracking from "../../tracking/Tracking";
|
|
import ErrorScreen from "./pages/ErrorScreen";
|
|
import { intl, t } from "../../../../../intl/index.native";
|
|
import { getTabTitle, getSearchTabFetchId, getSearchContextId } from "../../../SearchUtils";
|
|
import SearchTabsPage, { SearchTabsPageContext } from "./SearchTabsPage";
|
|
import SearchSessionAnalyticsManager from "../../../managers/native/SearchSessionAnalyticsManager";
|
|
import SearchPlatformUtils from "../../SearchPlatformUtils";
|
|
import { useSearchSegmentedControlState } from "./hooks/useSearchSegmentedControlState";
|
|
import { SwipeForMemberListContext } from "../../../../main_tabs_v2/native/channel/SwipeForMemberListWrapper";
|
|
import { Gesture } from "../../../../../_bundle/Module5273";
|
|
import { useSharedValue } from "../../../../reanimated/ReanimatedRexport";
|
|
import SearchPlatformActionCreators from "../../SearchPlatformActionCreators";
|
|
import SearchActionCreators from "../../../SearchActionCreators";
|
|
import SearchTabsFetchManager from "../../../managers/SearchTabsFetchManager";
|
|
import { ComponentDispatch } from "../../../../../utils/ComponentDispatchUtils";
|
|
import SearchTabsTransitionGroup from "./SearchTabsTransitionGroup";
|
|
import SearchTabsGradient from "./SearchTabsGradient";
|
|
import { SegmentedControlPages } from "../../../../../design/components/SegmentedControl/native/SegmentedControlPages.native";
|
|
import { useStateFromStoresObject } from "../../../../../_bundle/Module589";
|
|
import { useAutoSearchGuildChannelTab } from "../../hooks/useAutoSearchGuildChannelTab";
|
|
import { useAutoSearchMembersTab } from "../../hooks/useAutoSearchMembersTab";
|
|
import { useAutoSearchPeopleTab } from "../../hooks/useAutoSearchPeopleTab";
|
|
import { useAutoTrackSearchTabCountsViewedAnalytics } from "../../hooks/useAutoTrackSearchTabCountsViewedAnalytics";
|
|
let useStyles, c11009_16, __initData, __initData2, __initData3, Component;
|
|
const NoSearchResultsScreen = function NoSearchResultsScreen(props) {
|
|
const searchContext = props.searchContext;
|
|
useEffect(() => {
|
|
Tracking.trackSearchEmptyResult({
|
|
searchContext
|
|
});
|
|
}, [searchContext]);
|
|
return <ErrorScreen text={intl.string(t.V6nAfF)} />;
|
|
};
|
|
useStyles = createStyles({
|
|
controls: {
|
|
flex: 0,
|
|
minHeight: 32
|
|
},
|
|
pages: {
|
|
flex: 1
|
|
}
|
|
});
|
|
c11009_16 = debounce((a0) => Tracking.trackSearchTabSelected({
|
|
searchContext: a0
|
|
}), 500);
|
|
__initData = {
|
|
code: "function SearchTabsLayoutTsx1({contentOffset:contentOffset}){const{isDragging,disallowMemberListGesture}=this.__closure;var _disallowMemberListGe;isDragging.set(true);(_disallowMemberListGe=disallowMemberListGesture)===null||_disallowMemberListGe===void 0||_disallowMemberListGe.set(contentOffset.x>0);}"
|
|
};
|
|
__initData2 = {
|
|
code: "function SearchTabsLayoutTsx2(){const{isDragging,disallowMemberListGesture}=this.__closure;var _disallowMemberListGe;isDragging.set(false);(_disallowMemberListGe=disallowMemberListGesture)===null||_disallowMemberListGe===void 0||_disallowMemberListGe.set(false);}"
|
|
};
|
|
__initData3 = {
|
|
code: "function SearchTabsLayoutTsx3({contentOffset:contentOffset}){const{isDragging,disallowMemberListGesture}=this.__closure;if(isDragging.get()){var _disallowMemberListGe;(_disallowMemberListGe=disallowMemberListGesture)===null||_disallowMemberListGe===void 0||_disallowMemberListGe.set(contentOffset.x>0);}}"
|
|
};
|
|
Component = Module19.memo(function({ searchContext: searchContext2, visibleTabs, visibleTabCounts, width }) {
|
|
let selectedTab, setActiveIndex, callback, context, gesture, disallowGesture, channelId, screenIndex, sharedValue, callback2;
|
|
let visibleTabs2, setActiveIndex2, ref;
|
|
selectedTab = void 0;
|
|
setActiveIndex = void 0;
|
|
callback = void 0;
|
|
context = void 0;
|
|
gesture = void 0;
|
|
disallowGesture = void 0;
|
|
channelId = void 0;
|
|
screenIndex = void 0;
|
|
sharedValue = void 0;
|
|
callback2 = void 0;
|
|
const styles = useStyles();
|
|
const searchSegmentedControlState = useSearchSegmentedControlState({
|
|
items: useMemo(() => {
|
|
const r0 = [];
|
|
let c28035_0 = r0;
|
|
visibleTabs.forEach((visibleTab) => {
|
|
const r15 = {
|
|
label: getTabTitle(visibleTab),
|
|
id: visibleTab,
|
|
page: <SearchTabsPage tab={visibleTab} searchContext={searchContext2} width={width} />,
|
|
count: null
|
|
};
|
|
let count = visibleTabCounts == null ? void 0 : visibleTabCounts[visibleTab];
|
|
if (count == null) {
|
|
count = void 0;
|
|
}
|
|
r15.count = count;
|
|
c28035_0.push(r15);
|
|
});
|
|
return r0;
|
|
}, [visibleTabCounts, visibleTabs, searchContext2, width]),
|
|
visibleTabs,
|
|
onSelectedTabChange: useCallback((a0) => {
|
|
SearchSessionAnalyticsManager.setSelectedTab(searchContext2, a0);
|
|
c11009_16(searchContext2);
|
|
const searchTabFetchId = getSearchTabFetchId(searchContext2, SEARCH_MESSAGE_TAB_SENTINEL, SearchQueryStore.getQueryString(searchContext2));
|
|
const isFetching = SearchMessageStore.getIsFetching(searchTabFetchId);
|
|
const isInitialFetchComplete = SearchMessageStore.getIsInitialFetchComplete(searchTabFetchId);
|
|
const r29 = MESSAGE_SEARCH_RESULT_TABS_SET.has(a0);
|
|
if (!((r29 ? isInitialFetchComplete : !r29) || isFetching)) {
|
|
SearchPlatformUtils.fetchInitialMessagesDebounced(searchContext2);
|
|
}
|
|
}, [searchContext2]),
|
|
width
|
|
});
|
|
const segmentedControlState = searchSegmentedControlState.segmentedControlState;
|
|
selectedTab = searchSegmentedControlState.selectedTab;
|
|
setActiveIndex = segmentedControlState.setActiveIndex;
|
|
visibleTabs2 = visibleTabs;
|
|
setActiveIndex2 = setActiveIndex;
|
|
ref = void 0;
|
|
ref = useRef(() => {
|
|
setActiveIndex2(visibleTabs2.findIndex((item) => item === SearchTabs.MEDIA));
|
|
});
|
|
useEffect(() => {
|
|
ref.current = () => {
|
|
setActiveIndex2(visibleTabs2.findIndex((item) => item === SearchTabs.MEDIA));
|
|
};
|
|
}, [visibleTabs, setActiveIndex]);
|
|
callback = useCallback(() => ref.current(), []);
|
|
const memo2 = useMemo(() => ({
|
|
selectedTab,
|
|
selectMediaTab: callback
|
|
}), [callback, selectedTab]);
|
|
context = useContext(SwipeForMemberListContext);
|
|
const r58 = context == null ? {} : context;
|
|
gesture = r58.gesture;
|
|
disallowGesture = r58.disallowGesture;
|
|
channelId = r58.channelId;
|
|
screenIndex = r58.screenIndex;
|
|
const memo = useMemo(() => {
|
|
if (gesture != null) {
|
|
return Gesture.Native().simultaneousWithExternalGesture(gesture);
|
|
}
|
|
}, [gesture]);
|
|
sharedValue = useSharedValue(false);
|
|
const D = function D({ contentOffset }) {
|
|
sharedValue.set(true);
|
|
if (disallowGesture != null) {
|
|
disallowGesture.set(contentOffset.x > 0);
|
|
}
|
|
};
|
|
D.__closure = {
|
|
isDragging: sharedValue,
|
|
disallowMemberListGesture: disallowGesture
|
|
};
|
|
D.__workletHash = 766628353255;
|
|
D.__initData = __initData;
|
|
const callback4 = useCallback(D, [disallowGesture, sharedValue]);
|
|
const G = function G() {
|
|
sharedValue.set(false);
|
|
if (disallowGesture != null) {
|
|
disallowGesture.set(false);
|
|
}
|
|
};
|
|
G.__closure = {
|
|
isDragging: sharedValue,
|
|
disallowMemberListGesture: disallowGesture
|
|
};
|
|
G.__workletHash = 5683301645106;
|
|
G.__initData = __initData2;
|
|
const callback3 = useCallback(G, [disallowGesture, sharedValue]);
|
|
const A = function A({ contentOffset }) {
|
|
if (sharedValue.get() && disallowGesture != null) {
|
|
disallowGesture.set(contentOffset.x > 0);
|
|
}
|
|
};
|
|
A.__closure = {
|
|
isDragging: sharedValue,
|
|
disallowMemberListGesture: disallowGesture
|
|
};
|
|
A.__workletHash = 229712012692;
|
|
A.__initData = __initData3;
|
|
const callback5 = useCallback(A, [disallowGesture, sharedValue]);
|
|
callback2 = useCallback(() => {
|
|
SearchPlatformActionCreators.deleteSearchQuery(searchContext2);
|
|
SearchActionCreators.clearAllSearchMesssages();
|
|
SearchActionCreators.clearSearchRecentMessages();
|
|
SearchTabsFetchManager.cleanUp(getSearchContextId(searchContext2));
|
|
}, [searchContext2]);
|
|
useEffect(() => {
|
|
if (context == null) {
|
|
return () => callback2();
|
|
}
|
|
}, [context, callback2]);
|
|
useEffect(() => {
|
|
const handleChannelDetailsHidden2 = function handleChannelDetailsHidden({ channelId: channelId2, screenIndex: screenIndex2 }) {
|
|
if (channelId2 === channelId && screenIndex2 === screenIndex) {
|
|
setActiveIndex(0, false, true);
|
|
callback2();
|
|
}
|
|
};
|
|
if (context != null) {
|
|
ComponentDispatch.subscribe(ComponentActions.CHANNEL_DETAILS_HIDDEN, handleChannelDetailsHidden2);
|
|
return () => {
|
|
ComponentDispatch.unsubscribe(ComponentActions.CHANNEL_DETAILS_HIDDEN, handleChannelDetailsHidden2);
|
|
};
|
|
}
|
|
}, [channelId, screenIndex, setActiveIndex, context, callback2]);
|
|
return segmentedControlState.items.length === 0 ? <NoSearchResultsScreen searchContext={searchContext2} /> : <>
|
|
{[<View style={styles.controls}>
|
|
<SearchTabsTransitionGroup state={segmentedControlState} />
|
|
<SearchTabsGradient state={segmentedControlState} />
|
|
</View>, <View style={styles.pages}>
|
|
<SearchTabsPageContext.Provider value={memo2}>
|
|
<SegmentedControlPages state={segmentedControlState} bounces={context == null} nativeGesture={memo} onBeginDragWorklet={context != null ? callback4 : void 0} onEndDragWorklet={context != null ? callback3 : void 0} onScrollWorklet={context != null ? callback5 : void 0} />
|
|
</SearchTabsPageContext.Provider>
|
|
</View>]}
|
|
</>;
|
|
});
|
|
export default function ConnectedSearchTabsLayout(props) {
|
|
let candidateTabs;
|
|
const { searchContext: searchContext3, width: width2 } = props;
|
|
candidateTabs = void 0;
|
|
const stateFromStoresObject = useStateFromStoresObject([SearchTabsLayoutStore], () => ({
|
|
visibleTabs: SearchTabsLayoutStore.getVisibleTabs(searchContext3),
|
|
visibleTabCounts: SearchTabsLayoutStore.getVisibleTabCounts(searchContext3),
|
|
candidateTabs: SearchTabsLayoutStore.getCandidateTabs(searchContext3)
|
|
}), [searchContext3]);
|
|
const { visibleTabs: visibleTabs3, visibleTabCounts: visibleTabCounts2 } = stateFromStoresObject;
|
|
candidateTabs = stateFromStoresObject.candidateTabs;
|
|
const memo = useMemo(() => new Set(candidateTabs), [candidateTabs]);
|
|
useAutoSearchGuildChannelTab(searchContext3, !memo.has(SearchTabs.GUILD_CHANNELS));
|
|
useAutoSearchMembersTab(searchContext3, !memo.has(SearchTabs.MEMBERS));
|
|
useAutoSearchPeopleTab(searchContext3, !memo.has(SearchTabs.PEOPLE));
|
|
useAutoTrackSearchTabCountsViewedAnalytics({
|
|
searchContext: searchContext3,
|
|
visibleTabCounts: visibleTabCounts2,
|
|
visibleTabs: visibleTabs3
|
|
});
|
|
return <Component searchContext={searchContext3} visibleTabs={visibleTabs3} visibleTabCounts={visibleTabCounts2} width={width2} />;
|
|
};
|