Files
discord-decomp/modules/instant_invite/native/components/InstantInviteActionSheet.tsx
T
2026-11-01 12:12:55 +02:00

189 lines
8.8 KiB
TypeScript

// Metro module 8357 (f8358).
import { useCallback, useState } from "react";
import { ScrollView, View } from "react-native";
import StageInstanceStore from "../../../stage_channels/StageInstanceStore";
import CreateInviteModalStore from "../../../../stores/CreateInviteModalStore";
import GuildStore from "../../../../stores/GuildStore";
import PermissionStore from "../../../../stores/PermissionStore";
import { InviteTargetTypes } from "../../Constants";
import { Permissions } from "../../../../Constants";
import { createStyles } from "../../../../design/components/Styles/native/createStyles";
import Module712 from "../../../../_bundle/Module712";
import UserPlaceholderRow from "../../../main_tabs_v2/native/shared_components/user_list/UserPlaceholderRow";
import useSafeAreaInsets_native from "../../../safe_area/useSafeAreaInsets.native";
import useAnalyticsLocations, { AnalyticsLocationProvider } from "../../../app_analytics/useAnalyticsLocations";
import AnalyticsLocation from "../../../app_analytics/AnalyticsLocation";
import useGetOrFetchApplications from "../../../applications/useGetOrFetchApplications";
import { useStateFromStores } from "../../../../_bundle/Module589";
import { generateInviteKeyFromExtraData } from "../../InviteCodeUtils";
import getInviteURL from "../../getInviteURL";
import { getShareMessage, handleCopy, handleOpenShareSheet, handlePressSettings } from "../InstantInviteUtils";
import ActionSheetActionCreators from "../../../action_sheet/native/ActionSheetActionCreators";
import showUserProfileActionSheet from "../../../user_profile/native/showUserProfileActionSheet";
import { setHubProgressActionComplete } from "../../../hub/HubProgressActionCreators";
import { HubProgressStep } from "../../../../_bundle/Module1306";
import useInviteSuggestionRows from "../useInviteSuggestionRows";
import { BottomSheet } from "../../../../design/components/Sheet/native/BottomSheet.native";
import { BottomSheetTitleHeader } from "../../../../design/components/Sheet/native/BottomSheetTitleHeader.native";
import { intl, t } from "../../../../intl/index.native";
import { EmptyState } from "../../../../design/void/native";
import { AppCrash } from "../../../../design/components/Illustration/native/redesign/generated/AppCrash";
import InstantInviteEmptyState from "./InstantInviteEmptyState";
import InstantInviteShareApps from "./InstantInviteShareApps";
import { SearchField } from "../../../../design/components/TextField/native/SearchField.native";
import { searchInviteSuggestions } from "../../../../actions/InviteSuggestionsActionCreators";
import InstantInviteAgeText from "./InstantInviteAgeText";
import InstantInviteFriendsList from "./InstantInviteFriendsList";
let useStyles;
const Loading = function Loading() {
const styles = useStyles();
const r9 = [];
let key = 0;
while (true) {
r9.push(<UserPlaceholderRow key={key} row={key} />);
key = key + 1;
if (!(key < 10)) {
return <>
<View style={styles.placeholderHeader} />
<View style={styles.placeholderLabel} />
{r9}
</>;
}
}
};
useStyles = createStyles({
placeholderHeader: {
height: 16,
width: "80%",
margin: 16,
marginBottom: 8,
borderRadius: Module712.radii.sm,
backgroundColor: Module712.colors.BACKGROUND_MOD_MUTED
},
placeholderLabel: {
height: 16,
width: "40%",
margin: 16,
borderRadius: Module712.radii.sm,
backgroundColor: Module712.colors.BACKGROUND_MOD_MUTED
},
errorEmptyState: {
backgroundColor: "transparent"
},
searchAndShareContainer: {
borderTopWidth: 1,
borderColor: Module712.colors.BORDER_SUBTLE,
marginTop: Module712.space.PX_8,
paddingVertical: Module712.space.PX_8,
paddingHorizontal: Module712.space.PX_12,
flexDirection: "column",
gap: Module712.space.PX_12
},
inviteAgeText: {
paddingBottom: Module712.space.PX_8,
paddingHorizontal: Module712.space.PX_4
},
shareApps: {
paddingVertical: 0
}
});
export default function InstantInviteActionSheet(props) {
let children;
let shareMessage;
const { channel, source, vanityURLCode, guildScheduledEventId, targetApplicationId, code } = props;
shareMessage = void 0;
const styles = useStyles();
const bottom = useSafeAreaInsets_native().bottom;
const analyticsLocations = useAnalyticsLocations(AnalyticsLocation.INSTANT_INVITE_MODAL).analyticsLocations;
const [r41] = useGetOrFetchApplications(targetApplicationId != null ? [targetApplicationId] : []);
const stateFromStores = useStateFromStores([PermissionStore, CreateInviteModalStore, StageInstanceStore], () => {
if (code != null) {
return code;
}
if (channel.isGuildStageVoice() && !PermissionStore.can(Permissions.CREATE_INSTANT_INVITE, channel)) {
const stageInstanceByChannel = StageInstanceStore.getStageInstanceByChannel(channel.id);
if (stageInstanceByChannel?.invite_code != null) {
return stageInstanceByChannel.invite_code;
}
}
if (vanityURLCode != null) {
return guildScheduledEventId != null ? generateInviteKeyFromExtraData({
baseCode: vanityURLCode,
guildScheduledEventId
}) : vanityURLCode;
}
const invite = CreateInviteModalStore.getInvite();
return invite != null ? guildScheduledEventId != null ? generateInviteKeyFromExtraData({
baseCode: invite.code,
guildScheduledEventId
}) : invite.code : void 0;
});
const stateFromStores2 = useStateFromStores([CreateInviteModalStore], () => CreateInviteModalStore.getError());
const link = stateFromStores != null ? getInviteURL(stateFromStores) : null;
shareMessage = link != null ? getShareMessage(link) : "";
const r83 = targetApplicationId != null ? InviteTargetTypes.EMBEDDED_APPLICATION : null;
const callback3 = useCallback((a0) => {
ActionSheetActionCreators.hideActionSheet();
showUserProfileActionSheet({
userId: a0,
channelId: channel.id,
sourceAnalyticsLocations: analyticsLocations
});
}, [channel, analyticsLocations]);
const callback4 = useCallback((a0) => {
if (stateFromStores != null) {
a0({
channel,
code: stateFromStores,
message: shareMessage,
location: source
});
setHubProgressActionComplete(channel.getGuildId(), HubProgressStep.INVITE_USER);
}
}, [channel, stateFromStores, shareMessage, source]);
const callback2 = useCallback(() => {
setHubProgressActionComplete(channel.getGuildId(), HubProgressStep.INVITE_USER);
}, [channel]);
const callback = useCallback(() => handleCopy(stateFromStores, channel, source), [stateFromStores, channel, source]);
const callback5 = useCallback(() => handleOpenShareSheet(stateFromStores, channel, shareMessage, source), [stateFromStores, channel, shareMessage, source]);
const callback6 = useCallback(() => handlePressSettings(channel), [channel]);
const inviteSuggestionRows = useInviteSuggestionRows(channel, source, r83, targetApplicationId);
const { rows, isFetchingRows } = inviteSuggestionRows;
const r108 = stateFromStores == null || rows.length === 0 && isFetchingRows;
const [r117] = useState(stateFromStores != null && rows.length === 0 && !isFetchingRows);
const props2 = {
showGradient: stateFromStores2 != null || !r108 || !r117,
scrollable: true,
startExpanded: true,
header: <BottomSheetTitleHeader title={targetApplicationId != null ? r41 != null ? intl.formatToPlainString(t.ZdK3dW, {
applicationName: r41.name
}) : intl.string(t["OzOM/q"]) : intl.string(t["f1+QIK"])} />,
children: null
};
if (stateFromStores2 != null) {
children = <EmptyState style={styles.errorEmptyState} Illustration={AppCrash} title={stateFromStores2} />;
} else if (r108) {
children = <Loading />;
} else if (r117) {
children = <ScrollView contentContainerStyle={{
paddingBottom: bottom + 16
}}>
<InstantInviteEmptyState link={link} onCopy={callback} onShare={callback5} onPressSettings={callback6} />
</ScrollView>;
} else {
const r162 = [<InstantInviteShareApps contentContainerStyle={styles.shareApps} onItemPressed={callback4} />, <View style={styles.searchAndShareContainer}>
<SearchField size="md" isRound onChange={searchInviteSuggestions} placeholder={targetApplicationId != null ? intl.string(t.iI1gMg) : intl.formatToPlainString(t["1UgGdm"], {
groupname: GuildStore.getGuild(channel.guild_id)?.name
})} />
{!(vanityURLCode != null) && <InstantInviteAgeText style={styles.inviteAgeText} channel={channel} canEditInvite={code == null} />}
</View>];
children = <>
{[<View>{r162}</View>, <InstantInviteFriendsList data={rows} code={stateFromStores} source={source == null ? void 0 : source} onPressAvatar={callback3} onInviteSent={callback2} />]}
</>;
}
props2.children = children;
return <AnalyticsLocationProvider value={analyticsLocations}>
<BottomSheet {...props2} />
</AnalyticsLocationProvider>;
};