From b2ec934856139969a0fd0b4eed9c12b93f10aa05 Mon Sep 17 00:00:00 2001 From: Jordan Hewitt Date: Sun, 26 Jan 2025 06:41:06 -0800 Subject: [PATCH] start to develop conversationplay. --- app/(tabs)/index.tsx | 9 ++- components/ConversationPlay.tsx | 107 +++++++++++++++++++++++++++++++ components/LanguageSelection.tsx | 95 +++++++++++++-------------- 3 files changed, 160 insertions(+), 51 deletions(-) create mode 100644 components/ConversationPlay.tsx diff --git a/app/(tabs)/index.tsx b/app/(tabs)/index.tsx index 8b9b37e..291255a 100644 --- a/app/(tabs)/index.tsx +++ b/app/(tabs)/index.tsx @@ -1,10 +1,17 @@ import { LanguageSelection } from '@/components/LanguageSelection'; +import { useState } from 'react'; import { Text } from 'react-native'; import { Image, StyleSheet, Platform } from 'react-native'; +import { Conversation, Speaker } from '../lib/conversation'; +import { language_matrix_entry, Translator } from '../i18n/api'; export default function HomeScreen() { + + const [language, setLanguage] = useState() + return ( - + language ? : + setLanguage(l)} /> ); } diff --git a/components/ConversationPlay.tsx b/components/ConversationPlay.tsx new file mode 100644 index 0000000..9f49423 --- /dev/null +++ b/components/ConversationPlay.tsx @@ -0,0 +1,107 @@ + +interface ConversationPlayProps { + translator: Translator; +} + +function ConversationPlay (props : ConversationPlayProps) { + const [language, setLanguage] = useState(languages[0].code); + const [message, setMessage] = useState(''); + const [conversation, setConversation] = useState(null); + + const startConversation = () => { + const speaker: Speaker = { id: "user", language }; + const newConversation = new Conversation(translator, speaker); + setConversation(newConversation); + }; + + const addMessage = async () => { + if (conversation) { + conversation.addMessage({ id: "user", language }, message); + await conversation.translateLast(); + setMessage(''); + } + }; + + return ( + + Select Language: + {languages.map(lang => ( +