Skip to content

Commit a674213

Browse files
committed
Added Full Implementation of history
1 parent 0d6b543 commit a674213

File tree

6 files changed

+72
-309
lines changed

6 files changed

+72
-309
lines changed

App.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ function App(): JSX.Element {
3232
<Stack.Screen name={"ChatPage"} component={ChatPage} options={{
3333
headerShown:false
3434
}}/>
35-
<Stack.Screen name={"HistoryChatPage"} component={HistoryChatPage} options={{
36-
headerShown:false
37-
}}/>
3835
<Stack.Screen name={"MailPage"} component={MailPage} options={{
3936
headerShown:false
4037
}}/>

Components/ChatPage/Ai.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ function Ai({text}) {
4646
text: {
4747
color: 'rgb(236, 236, 236)',
4848
},
49+
blockquote: {
50+
backgroundColor: '#201d1d',
51+
color: 'rgba(243, 232, 130, 0.88)',
52+
fontSize: width * 0.033,
53+
borderRadius: 10,
54+
borderColor: 'rgba(243, 232, 130, 0.88)',
55+
},
4956
fence: {
5057
backgroundColor: '#080808',
5158
color: 'rgba(243, 232, 130, 0.88)',

Components/Homepage/EachHistorycard.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
/* eslint-disable react-native/no-inline-styles */
12
import {View, Text, TouchableOpacity, Dimensions} from 'react-native';
23
import React, {memo} from 'react';
34
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome';
4-
import {faPaperPlane} from '@fortawesome/free-solid-svg-icons';
5+
import {faPaperPlane, faTrash} from '@fortawesome/free-solid-svg-icons';
56

6-
function EachHistorycard({navigation, item}) {
7+
function EachHistorycard({navigation, item, index, deleteData}) {
78
function getFormattedData(text) {
89
if (text.length > 35) {
910
return text.slice(0, 35) + '...';
@@ -14,7 +15,8 @@ function EachHistorycard({navigation, item}) {
1415
const windowWidth = Dimensions.get('window').width;
1516
return (
1617
<TouchableOpacity
17-
onPress={() => navigation.navigate('ChatPage', {item})}
18+
onPress={() => navigation.navigate('ChatPage', {item, index})}
19+
key={index}
1820
style={{
1921
width: windowWidth * 0.9,
2022
height: 80,
@@ -26,13 +28,15 @@ function EachHistorycard({navigation, item}) {
2628
alignItems: 'center',
2729
paddingHorizontal: 20,
2830
}}>
29-
<Text style={{color: 'white'}}>{getFormattedData(item[0].message)}</Text>
30-
<FontAwesomeIcon
31-
icon={faPaperPlane}
32-
style={{
33-
color: 'white',
34-
}}
35-
/>
31+
<Text style={{color: 'white'}}>
32+
{getFormattedData(item[0]?.message ?? '')}
33+
</Text>
34+
<TouchableOpacity
35+
onPress={() => {
36+
deleteData(index);
37+
}}>
38+
<FontAwesomeIcon icon={faTrash} color="white" />
39+
</TouchableOpacity>
3640
</TouchableOpacity>
3741
);
3842
}

Screens/ChatPage.js

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ import {faMicrophone, faPaperPlane} from '@fortawesome/free-solid-svg-icons';
1616
const windowWidth = Dimensions.get('window').width;
1717

1818
export const ChatPage = ({navigation,route}) => {
19-
console.log(route.params);
2019
const dangerColor = 'rgba(172, 79, 79, 1.00)';
2120
const {History,setHistory,SaveData} = useContext(Context);
2221
const [scrollEnabled, setScrollEnabled] = useState(true);
2322
const Toast = useToast();
2423
const [loading,setloading] = useState(false);
2524
const [VoiceRecording,setVoiceRecording] = useState(false);
26-
const [requestBody,setRequestBody] = useState([
27-
]);
25+
const [requestBody,setRequestBody] = useState([]);
2826
const [value,setvalue] = useState('');
2927
const [chat,setchat] = useState([]);
3028
async function OnPressSend(val) {
@@ -103,23 +101,41 @@ export const ChatPage = ({navigation,route}) => {
103101
Voice.destroy().then(Voice.removeAllListeners);
104102
};
105103
}, []);
106-
//History
107-
useEffect(() => {
108-
if (chat.length === 2){
109-
const Prev = [...History];
110-
Prev.push([]);
111-
Prev[Prev.length - 1] = [...chat];
112-
setHistory(Prev);
113-
SaveData();
114-
// console.log(Prev)
115-
}
116-
if (chat.length > 2){
117-
const Prev = [...History];
118-
Prev[Prev.length - 1] = [...chat];
119-
setHistory(Prev);
120-
SaveData();
104+
useEffect(()=>{
105+
if (route.params){
106+
setchat(route.params.item);
107+
const requestBodyData = [];
108+
route.params.item.map((e)=>{
109+
requestBodyData.push({content:e.message});
110+
});
111+
setRequestBody(requestBodyData);
121112
}
122-
}, [chat]);
113+
},[]);
114+
//History
115+
useEffect(() => {
116+
if (!route.params){
117+
if (chat.length === 2){
118+
const Prev = [...History];
119+
Prev.unshift([]);
120+
Prev[0] = [...chat];
121+
setHistory(Prev);
122+
SaveData();
123+
// console.log(Prev)
124+
}
125+
if (chat.length > 2){
126+
const Prev = [...History];
127+
Prev[0] = [...chat];
128+
setHistory(Prev);
129+
SaveData();
130+
}} else {
131+
if (chat.length !== History.length && chat.length !== 0){
132+
const Prev = [...History];
133+
Prev[route.params.index] = [...chat];
134+
setHistory(Prev);
135+
SaveData();
136+
}
137+
}
138+
}, [chat]);
123139
const onSpeechStartHandler = (e) => {
124140
console.log('start handler==>>>', e);
125141
};

0 commit comments

Comments
 (0)