vn-verdnaturachat/app/views/serverNew.js

84 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-08-03 18:23:43 +00:00
import React from 'react';
2017-08-05 18:16:32 +00:00
import PropTypes from 'prop-types';
2017-08-09 13:12:00 +00:00
import { TextInput, StyleSheet } from 'react-native';
2017-08-07 00:34:35 +00:00
2017-08-09 20:18:00 +00:00
import RocketChat from '../lib/rocketchat';
2017-08-03 18:23:43 +00:00
2017-08-09 13:12:00 +00:00
import KeyboardView from '../components/KeyboardView';
2017-08-03 18:23:43 +00:00
const styles = StyleSheet.create({
view: {
flex: 1,
2017-08-07 00:34:35 +00:00
flexDirection: 'column',
2017-08-03 18:23:43 +00:00
justifyContent: 'center',
2017-08-07 00:34:35 +00:00
alignItems: 'stretch'
2017-08-03 18:23:43 +00:00
},
input: {
height: 40,
borderColor: '#aaa',
margin: 20,
padding: 5,
borderWidth: 0,
backgroundColor: '#f8f8f8'
2017-08-07 00:34:35 +00:00
},
text: {
textAlign: 'center',
color: '#888'
2017-08-03 18:23:43 +00:00
}
});
2017-08-05 18:16:32 +00:00
export default class NewServerView extends React.Component {
static propTypes = {
navigation: PropTypes.object.isRequired
}
2017-08-09 01:40:55 +00:00
static navigationOptions = () => ({
2017-08-07 00:34:35 +00:00
title: 'New Server Connection'
});
2017-08-03 18:23:43 +00:00
constructor(props) {
super(props);
this.state = {
2017-08-07 00:34:35 +00:00
defaultServer: 'https://demo.rocket.chat',
2017-08-03 18:23:43 +00:00
text: ''
};
this.submit = () => {
let url = this.state.text.trim();
if (!url) {
2017-08-07 00:34:35 +00:00
url = this.state.defaultServer;
2017-08-03 18:23:43 +00:00
}
// TODO: validate URL
2017-08-07 00:34:35 +00:00
if (url.indexOf('.') === -1) {
url = `https://${ url }.rocket.chat`;
}
if (/^https?:\/\//.test(url) === false) {
url = `https://${ url }`;
}
2017-08-03 18:23:43 +00:00
2017-08-09 16:40:03 +00:00
RocketChat.currentServer = url;
this.props.navigation.dispatch({ type: 'Navigation/BACK' });
2017-08-03 18:23:43 +00:00
};
}
render() {
return (
2017-08-09 13:12:00 +00:00
<KeyboardView style={styles.view}>
2017-08-03 18:23:43 +00:00
<TextInput
style={styles.input}
2017-08-05 18:16:32 +00:00
onChangeText={text => this.setState({ text })}
2017-08-03 18:23:43 +00:00
keyboardType='url'
autoCorrect={false}
returnKeyType='done'
autoCapitalize='none'
2017-08-05 18:16:32 +00:00
autoFocus
2017-08-03 18:23:43 +00:00
onSubmitEditing={this.submit}
2017-08-07 00:34:35 +00:00
placeholder={this.state.defaultServer}
2017-08-05 18:16:32 +00:00
/>
2017-08-09 13:12:00 +00:00
</KeyboardView>
2017-08-03 18:23:43 +00:00
);
}
}