Minor tweak

This commit is contained in:
Gerzon Z 2021-04-26 14:03:05 -04:00
parent 1ff77118f5
commit 69214bee93
2 changed files with 24 additions and 27 deletions

View File

@ -68,8 +68,8 @@ const styles = StyleSheet.create({
});
class CreateChannelView extends React.Component {
static navigationOptions = ({ route }) => ({
title: route?.params?.isTeam ? I18n.t('Create_Team') : I18n.t('Create_Channel')
static navigationOptions = () => ({
title: this.isTeam ? I18n.t('Create_Team') : I18n.t('Create_Channel')
})
static propTypes = {
@ -90,12 +90,17 @@ class CreateChannelView extends React.Component {
theme: PropTypes.string
};
state = {
constructor(props) {
super(props);
const { route } = this.props;
this.isTeam = route?.params?.isTeam || false;
this.state = {
channelName: '',
type: true,
readOnly: false,
encrypted: false,
broadcast: false
};
}
shouldComponentUpdate(nextProps, nextState) {
@ -156,9 +161,8 @@ class CreateChannelView extends React.Component {
channelName, type, readOnly, broadcast, encrypted
} = this.state;
const {
users: usersProps, isFetching, create, route
users: usersProps, isFetching, create
} = this.props;
const { isTeam } = route?.params;
if (!channelName.trim() || isFetching) {
return;
@ -169,7 +173,7 @@ class CreateChannelView extends React.Component {
// create channel or team
create({
name: channelName, users, type, readOnly, broadcast, encrypted, isTeam
name: channelName, users, type, readOnly, broadcast, encrypted, isTeam: this.isTeam
});
Review.pushPositiveEvent();
@ -201,13 +205,11 @@ class CreateChannelView extends React.Component {
renderType() {
const { type } = this.state;
const { route } = this.props;
const { isTeam } = route?.params;
return this.renderSwitch({
id: 'type',
value: type,
label: isTeam ? 'Private_Team' : 'Private_Channel',
label: this.isTeam ? 'Private_Team' : 'Private_Channel',
onValueChange: (value) => {
logEvent(events.CR_TOGGLE_TYPE);
// If we set the channel as public, encrypted status should be false
@ -218,13 +220,11 @@ class CreateChannelView extends React.Component {
renderReadOnly() {
const { readOnly, broadcast } = this.state;
const { route } = this.props;
const { isTeam } = route?.params;
return this.renderSwitch({
id: 'readonly',
value: readOnly,
label: isTeam ? 'Read_Only_Team' : 'Read_Only_Channel',
label: this.isTeam ? 'Read_Only_Team' : 'Read_Only_Channel',
onValueChange: (value) => {
logEvent(events.CR_TOGGLE_READ_ONLY);
this.setState({ readOnly: value });
@ -255,13 +255,11 @@ class CreateChannelView extends React.Component {
renderBroadcast() {
const { broadcast, readOnly } = this.state;
const { route } = this.props;
const { isTeam } = route?.params;
return this.renderSwitch({
id: 'broadcast',
value: broadcast,
label: isTeam ? 'Broadcast_Team' : 'Broadcast_Channel',
label: this.isTeam ? 'Broadcast_Team' : 'Broadcast_Channel',
onValueChange: (value) => {
logEvent(events.CR_TOGGLE_BROADCAST);
this.setState({
@ -316,9 +314,8 @@ class CreateChannelView extends React.Component {
render() {
const { channelName } = this.state;
const {
users, isFetching, route, theme
users, isFetching, theme
} = this.props;
const { isTeam } = route?.params;
const userCount = users.length;
return (
@ -328,18 +325,18 @@ class CreateChannelView extends React.Component {
keyboardVerticalOffset={128}
>
<StatusBar />
<SafeAreaView testID={isTeam ? 'create-team-view' : 'create-channel-view'}>
<SafeAreaView testID={this.isTeam ? 'create-team-view' : 'create-channel-view'}>
<ScrollView {...scrollPersistTaps}>
<View style={[sharedStyles.separatorVertical, { borderColor: themes[theme].separatorColor }]}>
<TextInput
autoFocus
style={[styles.input, { backgroundColor: themes[theme].backgroundColor }]}
label={isTeam ? I18n.t('Team_Name') : I18n.t('Channel_Name')}
label={this.isTeam ? I18n.t('Team_Name') : I18n.t('Channel_Name')}
value={channelName}
onChangeText={this.onChangeText}
placeholder={isTeam ? I18n.t('Team_Name') : I18n.t('Channel_Name')}
placeholder={this.isTeam ? I18n.t('Team_Name') : I18n.t('Channel_Name')}
returnKeyType='done'
testID={isTeam ? 'create-team-name' : 'create-channel-name'}
testID={this.isTeam ? 'create-team-name' : 'create-channel-name'}
autoCorrect={false}
autoCapitalize='none'
theme={theme}

View File

@ -113,7 +113,7 @@ class NewMessageView extends React.Component {
createChannel = () => {
logEvent(events.NEW_MSG_CREATE_CHANNEL);
const { navigation } = this.props;
navigation.navigate('SelectedUsersViewCreateChannel', { nextAction: () => navigation.navigate('CreateChannelView', { isTeam: false }) });
navigation.navigate('SelectedUsersViewCreateChannel', { nextAction: () => navigation.navigate('CreateChannelView') });
}
createTeam = () => {