-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChatInput.js
48 lines (42 loc) · 1.1 KB
/
ChatInput.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
TextInput,
} from 'react-native';
var styles = require('./Styles');
var getQuote = require('./getQuote');
class ChatInput extends Component {
constructor(props) {
super(props);
this.state = { text: '' };
}
postChatMessage(text, parent) {
parent.addRow(this.state.text, true);
parent.state.ws.send(this.state.text);
getQuote(parent.props.title, this.state.text)
.then((response) => response.text())
.then((responseText) => this.postQuote(responseText))
.catch((error) => console.warn(error))
this.setState({text: ''});
}
postQuote(quote) {
console.log(quote)
this.props.parent.addRow(quote);
}
render() {
return(
<TextInput
style={styles.chatInput}
returnKeyType='done'
placeholder="Write your messages here"
onChangeText={(text) => this.setState({text})}
onSubmitEditing={(text) =>
this.postChatMessage(text, this.props.parent)}
value={this.state.text}
/>
)
};
}
module.exports = ChatInput;