Skip to content

Commit 0fb1e04

Browse files
committed
Add send message bar
1 parent 5b93ab7 commit 0fb1e04

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

client/App.js

+24
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { PasswordModal } from "./components/PasswordModal";
22
import { Message } from "./components/Message"
33
import { FlatList, Text, View } from "react-native";
4+
const RNFS = require('react-native-fs');
45

56
export default function App() {
7+
const [message, setMessage] = useState("");
68
return (
79
<View
810
style={{
@@ -20,6 +22,14 @@ export default function App() {
2022
>
2123

2224
</FlatList>
25+
26+
<View style={{}}>
27+
<TextInput style={styles.textInput} secureTextEntry={true} onChangeText={setMessage}></TextInput>
28+
<Button title='Submit' onPress={() => {
29+
sendMessage(message);
30+
setMessage("");
31+
}} />
32+
</View>
2333
</View>
2434
);
2535
}
@@ -55,6 +65,19 @@ class MessageCmp {
5565
}
5666
}
5767

68+
function sendMessage(msg) {
69+
if (msg) {
70+
var newMsg = {
71+
type: 0,
72+
content: content.value,
73+
id: currId
74+
};
75+
socket.send(JSON.stringify(newMsg));
76+
sendMyMessage(content.value, currId);
77+
currId++;
78+
}
79+
}
80+
5881
function sendMessageInternal(msg) {
5982
messages.push(msg);
6083
}
@@ -86,6 +109,7 @@ function submitPassword(pwd) {
86109
.then(resp => resp.ok ? resp.text() : Promise.reject(`${resp.status}`))
87110
.then(async text => {
88111
token = text;
112+
//await RNFS.writeFile(RNFS.DocumentDirectoryPath + '/token.dat', token, 'utf8');
89113
//await filesystem.writeAsync(token);
90114
openMessageConnection();
91115
})

0 commit comments

Comments
 (0)