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

45 lines
2.3 KiB
TypeScript

// Metro module 11527 (f11528).
import { memo, useCallback } from "react";
import ChannelStore from "../../../stores/ChannelStore";
import UserStore from "../../../stores/UserStore";
import LurkingStore from "../LurkingStore";
import { JoinGuildSources } from "../../../Constants";
import { useStateFromStores } from "../../../_bundle/Module589";
import { setHubProgressActionComplete } from "../../hub/HubProgressActionCreators";
import { HubProgressStep } from "../../../_bundle/Module1306";
import { trackJoinClicked } from "../LurkerPreviewAnalytics";
import LurkerPreviewManager from "../LurkerPreviewManager";
import GuildActionCreators from "../../../actions/GuildActionCreators";
import { Button } from "../../../design/components/Button/native/Button.native";
import { intl, t } from "../../../intl/index.native";
import AvatarUtils from "../../../utils/AvatarUtils";
import UserUtils from "../../../utils/UserUtils";
const r29 = memo(function LurkerServerPreviewJoinButton(props) {
const { guildId, joinSource, onBeforeJoin } = props;
const stateFromStores = useStateFromStores([UserStore], () => UserStore.getCurrentUser());
const callback = useCallback(() => {
const lurkingSourceForGuild = LurkingStore.getLurkingSourceForGuild(guildId);
if (lurkingSourceForGuild?.type === JoinGuildSources.DIRECTORY_ENTRY) {
const channel = ChannelStore.getChannel(lurkingSourceForGuild.directoryChannelId);
if (channel != null) {
setHubProgressActionComplete(channel.getGuildId(), HubProgressStep.JOIN_GUILD);
}
}
trackJoinClicked(guildId, joinSource, LurkerPreviewManager.hasNavigatedAway(guildId));
if (onBeforeJoin != null) {
onBeforeJoin();
}
GuildActionCreators.joinGuild(guildId, {
source: joinSource
});
}, [guildId, joinSource, onBeforeJoin]);
if (stateFromStores == null) {
return <Button grow variant="primary" size="md" text={intl.string(t.VJlc0S)} onPress={callback} />;
}
const userAvatarSource = AvatarUtils.getUserAvatarSource(stateFromStores, false);
return <Button grow variant="primary" size="md" text={intl.formatToPlainString(t["5qtVhX"], {
usernameHook: () => UserUtils.getFormattedName(stateFromStores)
})} icon={<Button.Icon source={userAvatarSource} variant="entity" />} onPress={callback} />;
});
export default r29;