// src/components/MessageItem.tsx import React, { memo, useEffect, useRef, useState }…
- User
// src/components/MessageItem.tsx
import React, { memo, useEffect, useRef, useState } from 'react'; import { View, StyleSheet, TouchableOpacity, Animated } from 'react-native'; import { Message } from '../types/types'; import Markdown from 'react-native-markdown-display'; import { useApp } from '../context/AppContext';
interface MessageItemProps { message: Message; onLongPress?: () => void; }
const MessageItem: React.FC = memo(({ message, onLongPress }) => { const { currentTheme } = useApp(); const [timer, setTimer] = useState(0); const timerRef = useRef<NodeJS.Timeout | null>(null);
useEffect(() => { if (message.status === 'pending') { // Start timer timerRef.current = setInterval(() => { setTimer(prevTimer => prevTimer + 0.1); }, 100);
codereturn () => { if (timerRef.current) { clearInterval(timerRef.current); } }; }}, [message.status]);
useEffect(() => { if (message.status === 'pending' && timer >= 30) { // Optional: Max 30 seconds if (timerRef.current) { clearInterval(timerRef.current); } } }, [timer, message.status]);
return ( <View style={[ styles.container, message.isUser ? styles.userContainer : styles.assistantContainer, ]} > <TouchableOpacity onLongPress={onLongPress} activeOpacity={0.7} style={[ styles.messageBubble, message.isUser ? styles.userBubble : styles.assistantBubble, { backgroundColor: message.isUser ? currentTheme.accentColor : currentTheme.cardBackground }, { shadowColor: currentTheme.shadowColor }, ]} > {message.status === 'pending' ? ( <Markdown style={{ body: { fontSize: 16, fontFamily: 'Poppins_400Regular', color: message.isUser ? currentTheme.buttonTextColor : currentTheme.textColor, }, strong: { fontFamily: 'Poppins_700Bold', }, em: { fontFamily: 'Poppins_400Regular', fontStyle: 'italic', }, // Diğer Markdown stilleri eklenebilir }} > {
💬 ${timer.toFixed(1)}s} ) : ( <Markdown style={{ body: { fontSize: 16, fontFamily: 'Poppins_400Regular', color: message.isUser ? currentTheme.buttonTextColor : currentTheme.textColor, }, strong: { fontFamily: 'Poppins_700Bold', }, em: { fontFamily: 'Poppins_400Regular', fontStyle: 'italic', }, // Diğer Markdown stilleri eklenebilir }} > {message.text} )} ); });MessageItem.displayName = 'MessageItem';
const styles = StyleSheet.create({ assistantBubble: { borderTopLeftRadius: 0, }, assistantContainer: { justifyContent: 'flex-start', paddingRight: 0, alignSelf: 'flex-start', }, container: { flexDirection: 'row', marginVertical: 4, paddingHorizontal: 10, }, messageBubble: { borderRadius: 16, maxWidth: '80%', paddingHorizontal: 12, paddingVertical: 8, shadowOffset: { width: 0, height: 1, }, shadowOpacity: 0.2, shadowRadius: 1.41, elevation: 2, }, userBubble: { borderTopRightRadius: 0, }, userContainer: { justifyContent: 'flex-end', paddingLeft: 0, alignSelf: 'flex-end', }, });
- Assistant