s
This commit is contained in:
parent
384e607fe1
commit
76f2e6ed48
@ -1,9 +1,8 @@
|
||||
import { ThemedText } from "@/components/ThemedText";
|
||||
import { Message } from "@/types/ask";
|
||||
import { Dispatch, SetStateAction, useCallback, useRef } from "react";
|
||||
import { Dispatch, SetStateAction, useRef } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { StyleSheet, View } from 'react-native';
|
||||
import { createNewConversation } from "./utils";
|
||||
import { View } from 'react-native';
|
||||
|
||||
interface AskHelloProps {
|
||||
setUserMessages: Dispatch<SetStateAction<Message[]>>;
|
||||
@ -17,59 +16,59 @@ export default function AskHello({ setUserMessages, setConversationId, setIsHell
|
||||
//
|
||||
const inFlightRef = useRef(false);
|
||||
|
||||
const handleCase = useCallback(async (text: string) => {
|
||||
if (inFlightRef.current) return;
|
||||
inFlightRef.current = true;
|
||||
try {
|
||||
// UI
|
||||
setIsHello(false);
|
||||
// setUserMessages([
|
||||
// {
|
||||
// id: Math.random().toString(36).substring(2, 9),
|
||||
// content: text,
|
||||
// role: 'user',
|
||||
// timestamp: new Date().toISOString()
|
||||
// },
|
||||
// {
|
||||
// id: Math.random().toString(36).substring(2, 9),
|
||||
// content: "keepSearchIng",
|
||||
// role: 'assistant',
|
||||
// timestamp: new Date().toISOString()
|
||||
// }
|
||||
// ]);
|
||||
|
||||
const sessionId = await createNewConversation(text);
|
||||
if (!sessionId) {
|
||||
console.error("Failed to create a new conversation.");
|
||||
//
|
||||
// setUserMessages(prev => prev.filter(item => item.content !== 'keepSearchIng'));
|
||||
return;
|
||||
}
|
||||
|
||||
setConversationId(sessionId);
|
||||
// const handleCase = useCallback(async (text: string) => {
|
||||
// if (inFlightRef.current) return;
|
||||
// inFlightRef.current = true;
|
||||
// try {
|
||||
// if (webSocketManager && typeof (webSocketManager as any).send === 'function') {
|
||||
// (webSocketManager as any).send({
|
||||
// type: 'Chat',
|
||||
// session_id: sessionId,
|
||||
// message: text
|
||||
// });
|
||||
// } else {
|
||||
// throw new Error('WebSocket manager is not ready');
|
||||
// }
|
||||
// } catch (wsErr) {
|
||||
// console.error('WebSocket send failed:', wsErr);
|
||||
// // UI
|
||||
// setIsHello(false);
|
||||
// // setUserMessages([
|
||||
// // {
|
||||
// // id: Math.random().toString(36).substring(2, 9),
|
||||
// // content: text,
|
||||
// // role: 'user',
|
||||
// // timestamp: new Date().toISOString()
|
||||
// // },
|
||||
// // {
|
||||
// // id: Math.random().toString(36).substring(2, 9),
|
||||
// // content: "keepSearchIng",
|
||||
// // role: 'assistant',
|
||||
// // timestamp: new Date().toISOString()
|
||||
// // }
|
||||
// // ]);
|
||||
|
||||
// const sessionId = await createNewConversation(text);
|
||||
// if (!sessionId) {
|
||||
// console.error("Failed to create a new conversation.");
|
||||
// //
|
||||
// setUserMessages(prev => prev.filter(item => item.content !== 'keepSearchIng'));
|
||||
// // setUserMessages(prev => prev.filter(item => item.content !== 'keepSearchIng'));
|
||||
// return;
|
||||
// }
|
||||
} catch (err) {
|
||||
console.error('handleCase failed:', err);
|
||||
//
|
||||
// setUserMessages(prev => prev.filter(item => item.content !== 'keepSearchIng'));
|
||||
} finally {
|
||||
inFlightRef.current = false;
|
||||
}
|
||||
}, [setConversationId, setIsHello, setUserMessages]);
|
||||
|
||||
// setConversationId(sessionId);
|
||||
// // try {
|
||||
// // if (webSocketManager && typeof (webSocketManager as any).send === 'function') {
|
||||
// // (webSocketManager as any).send({
|
||||
// // type: 'Chat',
|
||||
// // session_id: sessionId,
|
||||
// // message: text
|
||||
// // });
|
||||
// // } else {
|
||||
// // throw new Error('WebSocket manager is not ready');
|
||||
// // }
|
||||
// // } catch (wsErr) {
|
||||
// // console.error('WebSocket send failed:', wsErr);
|
||||
// // //
|
||||
// // setUserMessages(prev => prev.filter(item => item.content !== 'keepSearchIng'));
|
||||
// // }
|
||||
// } catch (err) {
|
||||
// console.error('handleCase failed:', err);
|
||||
// //
|
||||
// // setUserMessages(prev => prev.filter(item => item.content !== 'keepSearchIng'));
|
||||
// } finally {
|
||||
// inFlightRef.current = false;
|
||||
// }
|
||||
// }, [setConversationId, setIsHello, setUserMessages]);
|
||||
|
||||
return (
|
||||
<View className="flex-1 bg-white w-full">
|
||||
@ -126,23 +125,23 @@ export default function AskHello({ setUserMessages, setConversationId, setIsHell
|
||||
}
|
||||
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
caseContainer: {
|
||||
flexDirection: 'row',
|
||||
flexWrap: 'wrap',
|
||||
justifyContent: 'center',
|
||||
width: '100%',
|
||||
marginTop: 16
|
||||
},
|
||||
case: {
|
||||
borderWidth: 1,
|
||||
borderColor: "#AC7E35",
|
||||
borderRadius: 10,
|
||||
paddingHorizontal: 8,
|
||||
marginHorizontal: 4,
|
||||
marginVertical: 4,
|
||||
width: 'auto',
|
||||
fontSize: 14,
|
||||
color: "#4C320C"
|
||||
}
|
||||
})
|
||||
// const styles = StyleSheet.create({
|
||||
// caseContainer: {
|
||||
// flexDirection: 'row',
|
||||
// flexWrap: 'wrap',
|
||||
// justifyContent: 'center',
|
||||
// width: '100%',
|
||||
// marginTop: 16
|
||||
// },
|
||||
// case: {
|
||||
// borderWidth: 1,
|
||||
// borderColor: "#AC7E35",
|
||||
// borderRadius: 10,
|
||||
// paddingHorizontal: 8,
|
||||
// marginHorizontal: 4,
|
||||
// marginVertical: 4,
|
||||
// width: 'auto',
|
||||
// fontSize: 14,
|
||||
// color: "#4C320C"
|
||||
// }
|
||||
// })
|
||||
Loading…
x
Reference in New Issue
Block a user