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-03 18:23:43 +00:00
|
|
|
import { View, TextInput, StyleSheet } from 'react-native';
|
|
|
|
import realm from './realm';
|
|
|
|
import { connect } from './meteor';
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
view: {
|
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'row',
|
|
|
|
justifyContent: 'center',
|
|
|
|
alignItems: 'center'
|
|
|
|
},
|
|
|
|
input: {
|
|
|
|
height: 40,
|
|
|
|
flex: 1,
|
|
|
|
borderColor: '#aaa',
|
|
|
|
margin: 20,
|
|
|
|
padding: 5,
|
|
|
|
borderWidth: 0,
|
|
|
|
backgroundColor: '#f8f8f8'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const defaultServer = 'http://localhost:3000';
|
|
|
|
|
2017-08-05 18:16:32 +00:00
|
|
|
export default class NewServerView extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
navigation: PropTypes.object.isRequired
|
|
|
|
}
|
|
|
|
|
2017-08-03 18:23:43 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
text: ''
|
|
|
|
};
|
|
|
|
|
|
|
|
const { navigate } = this.props.navigation;
|
|
|
|
|
|
|
|
this.submit = () => {
|
|
|
|
let url = this.state.text.trim();
|
|
|
|
if (!url) {
|
|
|
|
url = defaultServer;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: validate URL
|
|
|
|
|
|
|
|
realm.write(() => {
|
2017-08-05 18:16:32 +00:00
|
|
|
realm.objects('servers').filtered('current = true').forEach(item => (item.current = false));
|
|
|
|
realm.create('servers', { id: url, current: true }, true);
|
2017-08-03 18:23:43 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
connect(() => {
|
|
|
|
console.log('Site_Name', realm.objectForPrimaryKey('settings', 'Site_Name'));
|
|
|
|
navigate('Login');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View style={styles.view}>
|
|
|
|
<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-05 18:16:32 +00:00
|
|
|
placeholder={defaultServer}
|
|
|
|
/>
|
2017-08-03 18:23:43 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|