Files
discord-decomp/modules/launchpad/native/LaunchPadSearchResults.tsx
T
2026-11-01 12:12:55 +02:00

268 lines
10 KiB
TypeScript

// Metro module 15802 (f15803).
import { memo, useCallback, useRef, useEffect } from "react";
import { View } from "react-native";
import LocaleStore from "../../user_settings/LocaleStore";
import GuildReadStateStore from "../../../stores/GuildReadStateStore";
import GuildStore from "../../../stores/GuildStore";
import { UnreadSetting } from "../../read_states/ReadStateConstants";
import { createStyles } from "../../../design/components/Styles/native/createStyles";
import Module712 from "../../../_bundle/Module712";
import getLayoutStyles from "./shared/getLayoutStyles";
import { transitionToGuild } from "../../routing/transitionToGuild.native";
import { useStateFromStoresObject, useStateFromStores } from "../../../_bundle/Module589";
import { useFontScale } from "../../screen/native/useFontScale";
import renderChannelPressableWrapper from "./shared/renderChannelPressableWrapper";
import { PressableHighlight } from "../../../design/void/Pressables/native/Pressables";
import renderChannelWrapper from "./shared/renderChannelWrapper";
import UnreadBadge from "./shared/UnreadBadge";
import GuildIcon from "../../guild/native/GuildIcon";
import renderChannelContent from "./shared/renderChannelContent";
import renderChannelBadge from "./shared/renderChannelBadge";
import { AutocompleterResultTypes } from "../../autocompleter/index";
import TextChannel from "./shared/TextChannel";
import DMChannel from "./shared/DMChannel";
import VoiceOrStageChannel from "./shared/VoiceOrStageChannel";
import LaunchPadSearchResultUser from "./LaunchPadSearchResultUser";
import { renderCategoryItem, useCategoryStyles } from "../../channel_list_v2/native/items/RedesignCategory";
import { Text } from "../../../design/components/Text/native/Text";
import MobileVisualRefreshExperiment from "../../themes/experiments/MobileVisualRefreshExperiment";
import { intl, t } from "../../../intl/index.native";
import useWindowDimensions_native from "../../screen/useWindowDimensions.native";
import getScaledChannelRowHeight from "./shared/getScaledChannelRowHeight";
import FastList from "../../../lib/native/FastList";
let scrollIndicatorInsets, useStyles, Component, Component2, renderSearchResultsSection;
const renderItemJSX = function renderItemJSX({ result, categoryStyles, isRefreshEnabled: isRefreshEnabled3 }) {
if (result == null) {
return null;
}
const type = result.type;
if (AutocompleterResultTypes.GUILD === type) {
return <Component guild={result.record} />;
}
if (AutocompleterResultTypes.TEXT_CHANNEL === type) {
return <TextChannel channel={result.record} navigationReplace showGuildBadgeIcon />;
}
if (AutocompleterResultTypes.GROUP_DM === type) {
return <DMChannel channel={result.record} navigationReplace />;
}
if (AutocompleterResultTypes.VOICE_CHANNEL === type) {
return <VoiceOrStageChannel channel={result.record} />;
}
if (AutocompleterResultTypes.USER === type) {
return <LaunchPadSearchResultUser user={result.record} comparator={result.comparator} />;
}
if (AutocompleterResultTypes.HEADER === type) {
return renderCategoryItem({
name: result.record.text,
styles: categoryStyles,
isRefreshEnabled: isRefreshEnabled3
});
}
return <Text variant="text-sm/semibold">{result.type}</Text>;
};
renderSearchResultsSection = function renderSearchResultsSection() {
return <Component2 name={intl.string(t["zkoeq/"])} />;
};
scrollIndicatorInsets = {
bottom: 24
};
useStyles = createStyles({
listContainer: {
minHeight: 16
},
list: {
flex: -1,
marginTop: 8
},
guildIcon: {
borderRadius: Module712.radii.sm
},
categoryWrapper: {
backgroundColor: Module712.colors.BACKGROUND_BASE_LOW
},
pressable: {
flex: 1
},
pressableUnderlayColor: {
backgroundColor: Module712.colors.INTERACTIVE_BACKGROUND_ACTIVE
}
});
Component = memo(function({ guild }) {
const styles3 = useStyles();
const styles4 = getLayoutStyles();
const callback = useCallback(() => {
transitionToGuild(guild.id);
}, [guild.id]);
const stateFromStoresObject = useStateFromStoresObject([GuildReadStateStore], () => ({
unread: GuildReadStateStore.hasUnread(guild.id),
mentionCount: GuildReadStateStore.getMentionCount(guild.id),
isMentionLowImportance: GuildReadStateStore.getIsMentionLowImportance(guild.id)
}));
const { unread, mentionCount, isMentionLowImportance } = stateFromStoresObject;
const fontScale3 = useFontScale();
return renderChannelPressableWrapper(<PressableHighlight onPress={callback} underlayColor={styles3.pressableUnderlayColor.backgroundColor} style={[styles3.pressable, {
borderRadius: styles4.container.borderRadius
}]}>
{renderChannelWrapper(<>
<UnreadBadge unread={unread} resolvedUnreadSetting={UnreadSetting.ALL_MESSAGES} />
<GuildIcon size={styles4.icon.guildIconSize} guild={guild} style={[styles3.guildIcon, styles4.icon.margin]} />
{renderChannelContent({
name: guild.name,
mentionBadge: renderChannelBadge({
mentionCount,
locale: useStateFromStores([LocaleStore], () => LocaleStore.locale),
isMentionLowImportance
})
})}
</>, {
fontScale: fontScale3
})}
</PressableHighlight>);
});
Component2 = memo(function({ name, onPress, note }) {
return <View style={useStyles().categoryWrapper}>
{renderCategoryItem({
name,
onPress,
note,
styles: useCategoryStyles(),
isRefreshEnabled: MobileVisualRefreshExperiment("WrappedCategoryItem")
})}
</View>;
});
const r66 = memo(function InitialResultsInner(props) {
let children, props2;
let c22468_8, c22468_9, fontScale;
const { history: history2, unreads, toggleExpandedHistory, expandedHistory } = props;
let selectedGuildId2 = props.selectedGuildId;
const selectedGuildId = selectedGuildId2;
c22468_8 = void 0;
c22468_9 = void 0;
fontScale = void 0;
const styles3 = useStyles();
const styles = useCategoryStyles();
const isRefreshEnabled = MobileVisualRefreshExperiment("InitialResults");
const stateFromStores = useStateFromStores([GuildStore], () => {
if (selectedGuildId != null) {
return GuildStore.getGuild(selectedGuildId)?.name;
}
});
const height = useWindowDimensions_native().height;
const callback = useCallback((a0, a1) => renderItemJSX({
result: a0 === 0 ? history2[a1] : unreads[a1],
categoryStyles: styles,
isRefreshEnabled
}), [history2, unreads, styles, isRefreshEnabled]);
const r43 = unreads.some((unread) => unread.type === AutocompleterResultTypes.VOICE_CHANNEL);
c22468_8 = r43;
const callback2 = useCallback((a0) => {
let props, props2;
if (a0 === 0) {
const r47 = {
name: intl.string(t["Xmh+5e"]),
note: null,
onPress: null
};
const r52 = {
variant: "text-xs/semibold",
color: "text-brand",
children: null
};
if (expandedHistory) {
r52.children = intl.string(t["3BdvgI"]);
props2 = r52;
} else {
r52.children = intl.string(t["/XSoJ+"]);
props2 = r52;
}
r47.note = <Text {...props2} />;
r47.onPress = toggleExpandedHistory;
props = r47;
} else {
props = {
name: stateFromStores != null ? intl.formatToPlainString(c22468_8 ? t["+DrQVp"] : t["+lFj35"], {
guildName: stateFromStores
}) : intl.string(c22468_8 ? t.C5viSQ : t.ieCAhD)
};
}
return <Component2 {...props} />;
}, [toggleExpandedHistory, expandedHistory, stateFromStores, r43]);
const styles4 = getLayoutStyles();
c22468_9 = styles4;
fontScale = useFontScale();
const callback3 = useCallback((a0, a1) => a1 == null ? 0 : (a0 === 0 ? history2[a1] : unreads[a1]).type === AutocompleterResultTypes.VOICE_CHANNEL ? getScaledChannelRowHeight(fontScale) + c22468_9.voiceUsers.height - 2 : getScaledChannelRowHeight(fontScale), [fontScale, history2, unreads, styles4]);
const r60 = Math;
const length = history2.length;
const r67 = expandedHistory ? history2.length : Math.max(5 - unreads.length, 2);
L8: {
const r68 = r60.min(length, r67);
props2 = {
style: styles3.listContainer,
children: null
};
if (!(history2.length > 0)) {
const r3 = unreads.length > 0;
children = null;
if (!r3) {
break L8;
}
}
const props3 = {
optimizeListItemRender: true,
batchesToRender: 6,
style: styles3.list,
sectionSize: styles4.category.height,
itemSize: callback3,
renderItem: callback,
renderSection: callback2,
sections: [r68, unreads.length],
sectionFooterSize: 8,
footerSize: 8,
scrollIndicatorInsets,
chunkBase: height,
keyboardShouldPersistTaps: "always"
};
if (selectedGuildId == null) {
selectedGuildId2 = "default";
}
children = <FastList key={selectedGuildId2} {...props3} />;
}
props2.children = children;
return <View {...props2} />;
});
const r69 = memo(function SearchResultsInner(props) {
let ref, c22469_4, fontScale2;
const { results, query } = props;
ref = void 0;
c22469_4 = void 0;
fontScale2 = void 0;
const styles3 = useStyles();
const styles2 = useCategoryStyles();
const isRefreshEnabled2 = MobileVisualRefreshExperiment("SearchResults");
const height = useWindowDimensions_native().height;
const callback = useCallback((a0, a1) => renderItemJSX({
result: results[a1],
categoryStyles: styles2,
isRefreshEnabled: isRefreshEnabled2
}), [results, styles2, isRefreshEnabled2]);
ref = useRef(null);
useEffect(() => {
const current = ref.current;
if (current != null) {
const scrollToTop = current.scrollToTop;
if (scrollToTop != null) {
scrollToTop.call(current, false);
}
}
}, [query]);
const styles4 = getLayoutStyles();
c22469_4 = styles4;
fontScale2 = useFontScale();
const callback2 = useCallback((a0, a1) => a1 == null ? 0 : results[a1].type === AutocompleterResultTypes.VOICE_CHANNEL ? getScaledChannelRowHeight(fontScale2) + c22469_4.voiceUsers.height - 2 : getScaledChannelRowHeight(fontScale2), [fontScale2, results, styles4]);
return <View style={styles3.listContainer}>
{results.length > 0 ? <FastList ref={ref} optimizeListItemRender batchesToRender={6} style={styles3.list} sectionSize={styles4.category.height} itemSize={callback2} renderSection={renderSearchResultsSection} renderItem={callback} sections={[results.length]} footerSize={16} scrollIndicatorInsets={scrollIndicatorInsets} chunkBase={height} keyboardShouldPersistTaps="always" /> : null}
</View>;
});
export { r66 as InitialResults };
export { r69 as SearchResults };