chore: 注释掉一些use effect
This commit is contained in:
parent
b08f972678
commit
85a4771024
@ -1,7 +1,8 @@
|
||||
import ReturnArrow from "@/assets/icons/svg/returnArrow.svg";
|
||||
import Chat from "@/components/ask/chat";
|
||||
import AskHello from "@/components/ask/hello";
|
||||
import SendMessage from "@/components/ask/send";
|
||||
import { ThemedText } from "@/components/ThemedText";
|
||||
import { useWebSocketStreamHandler } from "@/hooks/useWebSocketStreamHandler";
|
||||
import { fetchApi } from "@/lib/server-api-util";
|
||||
import { WEBSOCKET_ENDPOINT } from "@/lib/websocket-util";
|
||||
import { Message } from "@/types/ask";
|
||||
@ -18,7 +19,7 @@ import {
|
||||
TouchableOpacity,
|
||||
View
|
||||
} from 'react-native';
|
||||
import { useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
|
||||
import Animated, { useAnimatedStyle, useSharedValue } from 'react-native-reanimated';
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
|
||||
export default function AskScreen() {
|
||||
@ -85,11 +86,11 @@ export default function AskScreen() {
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isHello && userMessages.length > 0 && isMountedRef.current) {
|
||||
scrollToEnd();
|
||||
}
|
||||
}, [userMessages, isHello, scrollToEnd]);
|
||||
// useEffect(() => {
|
||||
// if (!isHello && userMessages.length > 0 && isMountedRef.current) {
|
||||
// scrollToEnd();
|
||||
// }
|
||||
// }, [userMessages, isHello, scrollToEnd]);
|
||||
|
||||
useEffect(() => {
|
||||
const keyboardDidShowListener = Keyboard.addListener(
|
||||
@ -132,11 +133,11 @@ export default function AskScreen() {
|
||||
}, [isHello, scrollToEnd]);
|
||||
|
||||
// 使用新的WebSocket流处理hook,使用实时模式
|
||||
const { subscribeToWebSocket } = useWebSocketStreamHandler({
|
||||
setUserMessages,
|
||||
isMounted: true, // 传递静态值,hook内部会使用ref跟踪
|
||||
enableBatching: false // AskScreen使用实时模式
|
||||
});
|
||||
// const { subscribeToWebSocket } = useWebSocketStreamHandler({
|
||||
// setUserMessages,
|
||||
// isMounted: true, // 传递静态值,hook内部会使用ref跟踪
|
||||
// enableBatching: false // AskScreen使用实时模式
|
||||
// });
|
||||
|
||||
// useFocusEffect(
|
||||
// useCallback(() => {
|
||||
@ -169,10 +170,10 @@ export default function AskScreen() {
|
||||
});
|
||||
|
||||
// 触发动画
|
||||
useEffect(() => {
|
||||
fadeAnim.value = withTiming(isHello ? 1 : 0, { duration: 300 });
|
||||
fadeAnimChat.value = withTiming(isHello ? 0 : 1, { duration: 300 });
|
||||
}, [isHello]);
|
||||
// useEffect(() => {
|
||||
// fadeAnim.value = withTiming(isHello ? 1 : 0, { duration: 300 });
|
||||
// fadeAnimChat.value = withTiming(isHello ? 0 : 1, { duration: 300 });
|
||||
// }, [isHello]);
|
||||
|
||||
useEffect(() => {
|
||||
if (sessionId && isMountedRef.current) {
|
||||
@ -256,14 +257,14 @@ export default function AskScreen() {
|
||||
{WEBSOCKET_ENDPOINT}
|
||||
</ThemedText>
|
||||
{/* 欢迎页面 */}
|
||||
{/* <Animated.View
|
||||
<Animated.View
|
||||
style={[styles.absoluteView, welcomeStyle, { zIndex: 1 }]}
|
||||
>
|
||||
<AskHello setUserMessages={setUserMessages} setConversationId={setConversationId} setIsHello={setIsHello} />
|
||||
</Animated.View> */}
|
||||
<AskHello setUserMessages={setUserMessages} setConversationId={setConversationId} setIsHello={setIsHello} />
|
||||
</Animated.View>
|
||||
|
||||
{/* 聊天页面 */}
|
||||
{/* <Animated.View
|
||||
<Animated.View
|
||||
style={[styles.absoluteView, chatStyle, { zIndex: 0 }]}
|
||||
>
|
||||
<Chat
|
||||
@ -277,7 +278,7 @@ export default function AskScreen() {
|
||||
showsVerticalScrollIndicator={false}
|
||||
// onContentSizeChange={() => scrollToEnd()}
|
||||
/>
|
||||
</Animated.View> */}
|
||||
</Animated.View>
|
||||
</View>
|
||||
|
||||
{/* 输入框区域 */}
|
||||
|
||||
@ -88,7 +88,7 @@ class WebSocketManager {
|
||||
|
||||
const url = `${WEBSOCKET_ENDPOINT}?token=${token}`;
|
||||
console.log('WebSocket: 连接 URL:', url);
|
||||
|
||||
|
||||
try {
|
||||
this.ws = new WebSocket(url);
|
||||
} catch (error) {
|
||||
@ -111,7 +111,7 @@ class WebSocketManager {
|
||||
console.warn('WebSocket received empty message');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const message: WsMessage = JSON.parse(event.data);
|
||||
// console.log('WebSocket received message:', message)
|
||||
// 根据消息类型分发
|
||||
@ -183,7 +183,7 @@ class WebSocketManager {
|
||||
console.error('WebSocket 未连接,无法发送消息。');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
const messageString = JSON.stringify(message);
|
||||
this.ws.send(messageString);
|
||||
@ -321,10 +321,6 @@ export const getWebSocketManager = (): WebSocketManager => {
|
||||
return webSocketManagerInstance;
|
||||
};
|
||||
|
||||
// 为了向后兼容,仍然导出实例
|
||||
export const webSocketManager = getWebSocketManager();
|
||||
|
||||
|
||||
// webscoket 错误映射
|
||||
export const getWebSocketErrorMessage = (key: string, t: TFunction) => {
|
||||
const messages = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user