148 lines
5.7 KiB
TypeScript
148 lines
5.7 KiB
TypeScript
// Metro module 11848 (f11849).
|
|
import { useState, useLayoutEffect, useCallback } from "react";
|
|
import { ScrollView, View } from "react-native";
|
|
import GuildChannelStore from "../../../../stores/GuildChannelStore";
|
|
import GuildStore from "../../../../stores/GuildStore";
|
|
import { createStyles } from "../../../../design/components/Styles/native/createStyles";
|
|
import { NAV_BAR_HEIGHT } from "../../../../design/components/Navigator/native/NavigatorConstants.native";
|
|
import { useStateFromStores } from "../../../../_bundle/Module589";
|
|
import { useNavigation } from "../../../../design/components/Navigator/native/useNavigation.native";
|
|
import { getHeaderBackButton, getHeaderTextButton } from "../../../../design/components/Navigator/native/NavigatorHeader.native";
|
|
import { intl, t } from "../../../../intl/index.native";
|
|
import ChannelActionCreators from "../../../../actions/ChannelActionCreators";
|
|
import { APIError } from "../../../../errors/index";
|
|
import { SafeAreaPaddingView } from "../../../../components_native/common/SafeAreaView";
|
|
import GuildIcon from "../../../guild/native/GuildIcon";
|
|
import AvatarUtils from "../../../../utils/AvatarUtils";
|
|
import { Text } from "../../../../design/components/Text/native/Text";
|
|
import FreeFormInputGroup from "../../../../design/void/Form/native/FreeFormInputGroup";
|
|
import { Button } from "../../../../design/components/Button/native/Button.native";
|
|
import FreeFormErrorLabel from "../../../../design/void/Form/native/FreeFormErrorLabel";
|
|
const useStyles = createStyles({
|
|
flex: {
|
|
flex: 1
|
|
},
|
|
safePadding: {
|
|
marginTop: NAV_BAR_HEIGHT,
|
|
flex: 1
|
|
},
|
|
contentContainer: {
|
|
paddingHorizontal: 16
|
|
},
|
|
guildIcon: {
|
|
alignSelf: "center"
|
|
},
|
|
guildName: {
|
|
marginTop: 8,
|
|
textAlign: "center"
|
|
},
|
|
title: {
|
|
marginTop: 16,
|
|
textAlign: "center"
|
|
},
|
|
subTitle: {
|
|
marginTop: 8,
|
|
textAlign: "center"
|
|
},
|
|
topicInput: {
|
|
marginTop: 24
|
|
},
|
|
buttonWrapper: {
|
|
marginTop: 8
|
|
},
|
|
error: {
|
|
marginTop: 4
|
|
}
|
|
});
|
|
export default function ChannelPrompt(props) {
|
|
let state, setState, setState2, navigation;
|
|
const { guildId, buttonText, hasBack, hasSkip, onCancel, onSuccess } = props;
|
|
state = void 0;
|
|
setState = void 0;
|
|
setState2 = void 0;
|
|
navigation = void 0;
|
|
const styles = useStyles();
|
|
const stateFromStores = useStateFromStores([GuildStore], () => GuildStore.getGuild(guildId));
|
|
let onChangeText;
|
|
[state, onChangeText] = useState("");
|
|
let loading;
|
|
[loading, setState] = useState(false);
|
|
let state2;
|
|
[state2, setState2] = useState(null);
|
|
navigation = useNavigation();
|
|
useLayoutEffect(() => {
|
|
navigation.setOptions({
|
|
headerLeft: hasBack ? getHeaderBackButton(onCancel) : () => null,
|
|
headerRight: hasSkip ? getHeaderTextButton(intl.string(t["5Wxrcd"]), onSuccess) : () => null
|
|
});
|
|
}, [navigation, hasBack, hasSkip, onCancel, onSuccess]);
|
|
const callback = useCallback(async () => {
|
|
let c27196_2;
|
|
let c27196_3 = 0;
|
|
let c30470_0;
|
|
L12: {
|
|
try {
|
|
setState2(null);
|
|
setState(true);
|
|
const defaultChannel = GuildChannelStore.getDefaultChannel(guildId);
|
|
c27196_3 = 1;
|
|
await ChannelActionCreators.createTextChannel(guildId, state, defaultChannel?.parent_id, intl.formatToPlainString(t.V4lepJ, {
|
|
topic: state
|
|
}));
|
|
(0, onSuccess)();
|
|
c27196_3 = 0;
|
|
(0, setState)(false);
|
|
} catch ($e) {
|
|
const r34 = $e;
|
|
let r7 = r34;
|
|
c27196_2 = r34;
|
|
if (c27196_3 !== 0) {
|
|
while (true) {
|
|
try {
|
|
const r94 = c27196_2;
|
|
c27196_3 = 0;
|
|
c30470_0 = r94;
|
|
setState2(new APIError(c30470_0));
|
|
(0, setState)(false);
|
|
break L12;
|
|
} catch (r90) {
|
|
r7 = r90;
|
|
c27196_2 = r90;
|
|
if (c27196_3 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw r7;
|
|
}
|
|
}
|
|
}, [guildId, onSuccess, state]);
|
|
return stateFromStores == null ? null : <SafeAreaPaddingView top style={styles.safePadding}>
|
|
<ScrollView style={styles.flex} contentInset={{
|
|
top: 0
|
|
}} automaticallyAdjustContentInsets={false} keyboardShouldPersistTaps="handled" alwaysBounceVertical={false} contentContainerStyle={styles.contentContainer}>
|
|
<GuildIcon style={styles.guildIcon} value={stateFromStores.name} icon={stateFromStores.icon != null ? AvatarUtils.getGuildIconURL({
|
|
id: stateFromStores.id,
|
|
icon: stateFromStores.icon,
|
|
canAnimate: true,
|
|
size: 128
|
|
}) : null} selected />
|
|
<Text style={styles.guildName} lineClamp={1} variant="text-sm/semibold" color="mobile-text-heading-primary">{stateFromStores.name}</Text>
|
|
<Text style={styles.title} accessibilityRole="header" variant="heading-xl/extrabold" color="mobile-text-heading-primary">
|
|
{intl.string(t["8VRa7d"])}
|
|
</Text>
|
|
<Text style={styles.subTitle} variant="text-sm/medium" color="text-default">
|
|
{intl.string(t["+855Pm"])}
|
|
</Text>
|
|
<FreeFormInputGroup style={styles.topicInput} label={intl.string(t.bY20tU)} value={state} error={state2 == null ? void 0 : state2.getFirstFieldErrorMessage("name")} onChangeText={onChangeText} onSubmitEditing={callback} maxLength={100} placeholder={intl.string(t.xGOYA8)} returnKeyType="done" autoFocus />
|
|
<View style={styles.buttonWrapper}>
|
|
<Button size="md" text={buttonText} onPress={callback} loading={loading} disabled={loading} grow />
|
|
</View>
|
|
{(state2 == null ? void 0 : state2.hasFieldErrors()) ? <FreeFormErrorLabel style={styles.error}>
|
|
{state2 == null ? void 0 : state2.getAnyErrorMessage()}
|
|
</FreeFormErrorLabel> : null}
|
|
</ScrollView>
|
|
</SafeAreaPaddingView>;
|
|
};
|