Skip to content

Commit 0d6b543

Browse files
committed
Added history
1 parent c9f0c72 commit 0d6b543

File tree

4 files changed

+128
-80
lines changed

4 files changed

+128
-80
lines changed

Components/ChatPage/AiThinking.js

Lines changed: 58 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,61 @@
1-
import {useContext, useState} from "react";
2-
import Context from "../../Context/Context";
3-
import {Clipboard, Text, TouchableOpacity, View} from "react-native";
4-
import {FontAwesomeIcon} from "@fortawesome/react-native-fontawesome";
5-
import {faCopy, faRobot} from "@fortawesome/free-solid-svg-icons";
6-
import TypeWriter from "react-native-typewriter";
1+
/* eslint-disable react/react-in-jsx-scope */
2+
/* eslint-disable react-native/no-inline-styles */
3+
import {useContext, useState} from 'react';
4+
import Context from '../../Context/Context';
5+
import {Clipboard, Dimensions, Text, TouchableOpacity, View} from 'react-native';
6+
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome';
7+
import {faCopy, faRobot} from '@fortawesome/free-solid-svg-icons';
8+
import TypeWriter from 'react-native-typewriter';
79

810
export const AiThinking = () => {
9-
const [random,setRandom]=useState(Math.floor(Math.random() * 7))
10-
const Dailogs = [
11-
"Thinking...💭",
12-
"Till I am thinking your answer, Did you know:\nPeater Parker is Spiderman🕸️",
13-
"While I am thinking, Do you know:\n\"The Eiffel Tower can be 15 cm taller during the summer🧠\"",
14-
"Your response is on the route...🚗",
15-
"Your answer is on the way, Till the time here is a fun fact:\n\"Scotland's national animal is unicorn!🫏\"",
16-
"Spinning the hamster wheel of progress...🐭",
17-
"Riding the waves of data...👩‍💻"
18-
]
19-
const [writing,setWriting]=useState(1)
20-
return (
21-
<View style={{
22-
backgroundColor:Style1.color5,
23-
elevation:1,
24-
marginVertical:10
11+
const [random, setRandom] = useState(Math.floor(Math.random() * 7));
12+
const Dailogs = [
13+
'Thinking...💭',
14+
'Till I am thinking your answer, Did you know:\nPeater Parker is Spiderman🕸️',
15+
'While I am thinking, Do you know:\n"The Eiffel Tower can be 15 cm taller during the summer🧠"',
16+
'Your response is on the route...🚗',
17+
'Your answer is on the way, Till the time here is a fun fact:\n"Scotland\'s national animal is unicorn!🫏"',
18+
'Spinning the hamster wheel of progress...🐭',
19+
'Riding the waves of data...👩‍💻',
20+
];
21+
const [writing, setWriting] = useState(1);
22+
const width = Dimensions.get('window').width;
23+
return (
24+
<View
25+
style={{
26+
padding: width * 0.02,
27+
marginVertical: 4,
28+
}}>
29+
<View
30+
style={{
31+
backgroundColor: '#5248a8',
32+
alignSelf: 'flex-end',
33+
fontSize: 17,
34+
borderRadius: 10,
35+
padding: width * 0.04,
2536
}}>
26-
<View style={{
27-
paddingHorizontal:10,
28-
paddingTop:10,
29-
flexDirection:"row",
30-
alignItems:"center",
31-
}}>
32-
<FontAwesomeIcon icon={ faRobot } style={{
33-
padding:10,
34-
color:Style1.color2
35-
}}/>
36-
<Text style={{
37-
color:Style1.color2,
38-
fontSize:17,
39-
paddingLeft:5
40-
}}>Thinking...</Text>
41-
</View>
42-
<View style={{
43-
padding:15,
44-
paddingTop:2,
45-
paddingLeft:27,
46-
marginTop:3,
47-
fontSize:17,
48-
}}>
49-
<TypeWriter minDelay={1} maxDelay={1} typing={writing} style={{
50-
color:Style1.color4
51-
}} onTypingEnd={()=>{
52-
if(writing===-1){
53-
setRandom(Math.floor(Math.random() * 7))
54-
setTimeout(()=>{
55-
setWriting(1)
56-
},1000)
57-
58-
}else {
59-
setTimeout(()=>{
60-
setWriting(-1)
61-
},5000)
62-
}
63-
}}>{Dailogs[random]}</TypeWriter>
64-
</View>
65-
66-
</View>
67-
)
68-
}
37+
<TypeWriter
38+
minDelay={1}
39+
maxDelay={1}
40+
typing={writing}
41+
style={{
42+
color: 'white',
43+
}}
44+
onTypingEnd={() => {
45+
if (writing === -1) {
46+
setRandom(Math.floor(Math.random() * 7));
47+
setTimeout(() => {
48+
setWriting(1);
49+
}, 1000);
50+
} else {
51+
setTimeout(() => {
52+
setWriting(-1);
53+
}, 5000);
54+
}
55+
}}>
56+
{Dailogs[random]}
57+
</TypeWriter>
58+
</View>
59+
</View>
60+
);
61+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import {View, Text, TouchableOpacity, Dimensions} from 'react-native';
2+
import React, {memo} from 'react';
3+
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome';
4+
import {faPaperPlane} from '@fortawesome/free-solid-svg-icons';
5+
6+
function EachHistorycard({navigation, item}) {
7+
function getFormattedData(text) {
8+
if (text.length > 35) {
9+
return text.slice(0, 35) + '...';
10+
} else {
11+
return text;
12+
}
13+
}
14+
const windowWidth = Dimensions.get('window').width;
15+
return (
16+
<TouchableOpacity
17+
onPress={() => navigation.navigate('ChatPage', {item})}
18+
style={{
19+
width: windowWidth * 0.9,
20+
height: 80,
21+
backgroundColor: '#372e6b',
22+
borderRadius: 10,
23+
marginVertical: 5,
24+
flexDirection: 'row',
25+
justifyContent: 'space-between',
26+
alignItems: 'center',
27+
paddingHorizontal: 20,
28+
}}>
29+
<Text style={{color: 'white'}}>{getFormattedData(item[0].message)}</Text>
30+
<FontAwesomeIcon
31+
icon={faPaperPlane}
32+
style={{
33+
color: 'white',
34+
}}
35+
/>
36+
</TouchableOpacity>
37+
);
38+
}
39+
40+
export default memo(EachHistorycard);

Screens/ChatPage.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1+
/* eslint-disable react-hooks/exhaustive-deps */
12
/* eslint-disable react-native/no-inline-styles */
23
/* eslint-disable react/react-in-jsx-scope */
34
/* eslint-disable prettier/prettier */
4-
import {Dimensions, FlatList, Image, PermissionsAndroid, ScrollView, Text, TextInput, TouchableOpacity, View} from 'react-native';
5-
import {useContext, useEffect, useRef, useState} from 'react';
5+
import {Dimensions, Image, PermissionsAndroid, TextInput, TouchableOpacity, View} from 'react-native';
6+
import {useContext, useEffect, useState} from 'react';
67
import Context from '../Context/Context';
78
import {TopHeader} from '../Components/Global/TopHeader';
89
import {useToast} from 'react-native-toast-notifications';
910
import axios from 'axios';
10-
import {AiThinking} from '../Components/ChatPage/AiThinking';
1111
import Voice from '@react-native-community/voice';
1212
import ChatScroll from '../Components/ChatPage/ChatScroll';
1313
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome';
1414
import {faMicrophone, faPaperPlane} from '@fortawesome/free-solid-svg-icons';
1515

1616
const windowWidth = Dimensions.get('window').width;
1717

18-
export const ChatPage = ({navigation}) => {
18+
export const ChatPage = ({navigation,route}) => {
19+
console.log(route.params);
1920
const dangerColor = 'rgba(172, 79, 79, 1.00)';
2021
const {History,setHistory,SaveData} = useContext(Context);
2122
const [scrollEnabled, setScrollEnabled] = useState(true);
@@ -174,6 +175,7 @@ export const ChatPage = ({navigation}) => {
174175
}}>
175176
<TopHeader navigation={navigation} text={'Chat'}/>
176177
<ChatScroll chat={chat} scrollEnabled={scrollEnabled}/>
178+
{/* <AiThinking/> */}
177179
<View style={{
178180
height:85,
179181
}} />

Screens/HomePage.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@ import {
88
TextInput,
99
Image,
1010
} from 'react-native';
11-
import React from 'react';
11+
import React, {useContext} from 'react';
12+
import Context from '../Context/Context';
13+
import EachHistorycard from '../Components/Homepage/EachHistorycard';
1214

1315
const windowWidth = Dimensions.get('window').width;
1416
const windowHeight = Dimensions.get('window').height;
1517

1618
export function HomePage({navigation}) {
19+
const {History} = useContext(Context);
20+
// console.log('====================================');
21+
// console.log(History);
22+
// console.log('====================================');
1723
return (
1824
<>
1925
<ScrollView
@@ -22,6 +28,9 @@ export function HomePage({navigation}) {
2228
backgroundColor: '#1e1b38',
2329
paddingHorizontal: windowWidth * 0.045,
2430
paddingTop: 10,
31+
}}
32+
contentContainerStyle={{
33+
paddingBottom: 100,
2534
}}>
2635
<Text
2736
style={{
@@ -83,7 +92,6 @@ export function HomePage({navigation}) {
8392
style={{
8493
flexDirection: 'row',
8594
alignItems: 'center',
86-
8795
paddingTop: 20,
8896
}}>
8997
<Text
@@ -95,15 +103,20 @@ export function HomePage({navigation}) {
95103
History
96104
</Text>
97105
</View>
98-
<View
99-
style={{
100-
flex: 1,
101-
justifyContent: 'center',
102-
alignItems: 'center',
103-
paddingTop: 100,
104-
}}>
105-
<Text style={{color: 'white'}}>No Chats 😕</Text>
106-
</View>
106+
{History.length === 0 && (
107+
<View
108+
style={{
109+
flex: 1,
110+
justifyContent: 'center',
111+
alignItems: 'center',
112+
paddingTop: 100,
113+
}}>
114+
{<Text style={{color: 'white'}}>No Chats 😕</Text>}
115+
</View>
116+
)}
117+
{History.reverse().map(item => (
118+
<EachHistorycard item={item} />
119+
))}
107120
</ScrollView>
108121
<TouchableOpacity
109122
onPress={() => navigation.navigate('ChatPage')}

0 commit comments

Comments
 (0)