Commit 7c5f12fd authored by Malsha Rathnasiri's avatar Malsha Rathnasiri

add default questions

parent c998912e
......@@ -9,6 +9,7 @@ import {
View,
Text,
SafeAreaView,
TouchableOpacity,
} from "react-native";
import { AudioRecorder } from "../components/AudioRecorder";
import _ from "lodash";
......@@ -23,13 +24,19 @@ import { CONVO_DEFAULT_ICON_COLOR, styles } from "../util/styles";
import { StatusBar } from "expo-status-bar";
import Slider from "@react-native-community/slider";
import { PlayMessage } from "../components/PlayMessage";
import { Toast, Input } from "native-base";
import { Toast, Input, ScrollView, Divider } from "native-base";
import { ERROR_TOAST_PROPS } from "../util/util";
import AsyncStorage from "@react-native-async-storage/async-storage";
export default function ChatScreen({ navigation }) {
const currentTime = new Date();
const QandAs = [
{ Q: "Does the bus come today? ", A: "Yes" },
{ Q: "What time the bus arrives? ", A: "10:30am" },
{ Q: "Im not coming today ", A: "Okay" },
];
const defaultChatData = [
{
id: 1,
......@@ -155,6 +162,15 @@ export default function ChatScreen({ navigation }) {
// }
useEffect(() => {
const interval = setInterval(() => {
loadChats();
}, 1000);
return () => {
clearInterval(interval);
};
}, []);
const loadChatDetails = async () => {
await getOne("conversations", 1)
.then((res) => {
......@@ -180,6 +196,38 @@ export default function ChatScreen({ navigation }) {
});
};
const onDefaultMessagePressed = (item) => {
try {
addChats({
message: item.Q,
from_user: chatDetails.from_user,
to_user: chatDetails.to_user,
conversation: chatDetails.id,
}).then((response) => {
// console.log(response)
});
setTimeout(() => {
addChats({
message: item.A,
from_user: chatDetails.to_user,
to_user: chatDetails.from_user,
conversation: chatDetails.id,
}).then((response) => {
// console.log(response)
});
}, 500);
setLoading(true);
setInput("");
loadChats();
} catch (e) {
Toast.show({
title: "Error sending message. try again!",
...ERROR_TOAST_PROPS,
});
}
};
const loadChats = async () => {
await getList("chats")
.then((res) => {
......@@ -238,7 +286,7 @@ export default function ChatScreen({ navigation }) {
<View
style={{
display: "flex",
flex: 0.8,
flex: 0.9,
justifyContent: "space-between",
}}
>
......@@ -336,8 +384,7 @@ export default function ChatScreen({ navigation }) {
new Date().toLocaleDateString()
) {
date = "Today";
}
else {
} else {
date = new Date(title).toLocaleDateString();
}
return <Text style={styles.header}>{date}</Text>;
......@@ -361,12 +408,37 @@ export default function ChatScreen({ navigation }) {
)
}} /> */}
</View>
<View style={{ flex: 0.075, padding: 0, backgroundColor: "white" }}>
<Divider />
<View style={{ flex: 0.05, padding: 0, backgroundColor: "white" }}>
<View
style={{ flexDirection: "row", display: "flex", height: "100%" }}
>
<ScrollView horizontal={true}>
{QandAs.map((item) => (
<TouchableOpacity
onPress={() => onDefaultMessagePressed(item)}
style={{
marginVertical: 5,
marginHorizontal: 5,
backgroundColor: "gray",
borderRadius: 5,
justifyContent: "center",
alignSelf: "center",
padding: 5,
}}
>
<Text
style={{ justifyContent: "center", alignSelf: "center" }}
>
{item.Q}
</Text>
</TouchableOpacity>
))}
</ScrollView>
</View>
</View>
<Divider />
<View style={{ flex: 0.05, padding: 0, backgroundColor: "white" }}>
<View
style={{ flexDirection: "row", display: "flex", height: "100%" }}
>
......@@ -382,7 +454,7 @@ export default function ChatScreen({ navigation }) {
defaultValue={input}
onChange={(e) => setInput(e.target.value)}></TextInput> */}
<Input
style={{}}
style={{ height: 30 }}
value={input}
w="100%"
onChangeText={setInput}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment