Files
EMI-ExpoAPP/components/NewComment.js
T

60 lines
1.9 KiB
JavaScript

import React, { useState } from 'react';
import { View, StyleSheet, Icon } from 'react-native';
import { TextInput, Button } from 'react-native-paper';
import API from './../API.js';
import { useNavigation } from '@react-navigation/native';
import AwesomeIcon from 'react-native-vector-icons/FontAwesome';
import i18n from "../i18nMessages.js";
let NewComment = ({ postid, newComentAdded }) => {
let [commentContent, setCommentContent] = useState('');
const navigation = useNavigation();
return (
<View style={styles.NewComment}>
<TextInput
label={i18n.t("message.newComment")}
value={commentContent}
onChangeText={setCommentContent}
mode="outlined"
multiline={true}
dense={true}
style={{
flex: 8,
fontSize: 12,
backgroundColor: "white",
}}
/>
<View style={{
flex: 2,
fontSize: 12,
flexDirection: "column",
alignItems: "center", // ignore this - we'll come back to it
justifyContent: "center",
}}>
<Button mode="outlined" onPress={() => {
if (commentContent.trim() === "") return 0;
setCommentContent('');
API.newPostComment(postid, commentContent).then((newPost) => {
setCommentContent('');
if(newComentAdded) newComentAdded(newPost);
});
}}>
<AwesomeIcon name="send" />
</Button>
</View>
</View>
);
}
export default NewComment;
const styles = StyleSheet.create({
NewComment: {
margin: 10,
flexDirection: "row",
flex: 6
}
});