File size: 30,427 Bytes
816fffb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>La Casseuse - French Language Tutor</title>
<script src="https://cdn.tailwindcss.com"></script>
<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
const { useState, useEffect, useRef } = React;
// Lucide Icons as inline SVG components
const Send = () => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><line x1="22" y1="2" x2="11" y2="13"></line><polygon points="22 2 15 22 11 13 2 9 22 2"></polygon></svg>;
const Loader2 = () => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" className="animate-spin"><line x1="12" y1="2" x2="12" y2="6"></line><line x1="12" y1="18" x2="12" y2="22"></line><line x1="4.93" y1="4.93" x2="7.76" y2="7.76"></line><line x1="16.24" y1="16.24" x2="19.07" y2="19.07"></line><line x1="2" y1="12" x2="6" y2="12"></line><line x1="18" y1="12" x2="22" y2="12"></line><line x1="4.93" y1="19.07" x2="7.76" y2="16.24"></line><line x1="16.24" y1="7.76" x2="19.07" y2="4.93"></line></svg>;
const Mic = () => <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"></path><path d="M19 10v2a7 7 0 0 1-14 0v-2"></path><line x1="12" y1="19" x2="12" y2="23"></line><line x1="8" y1="23" x2="16" y2="23"></line></svg>;
const MicOff = () => <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><line x1="1" y1="1" x2="23" y2="23"></line><path d="M9 9v3a3 3 0 0 0 5.12 2.12M15 9.34V4a3 3 0 0 0-5.94-.6"></path><path d="M17 16.95A7 7 0 0 1 5 12v-2m14 0v2a7 7 0 0 1-.11 1.23"></path><line x1="12" y1="19" x2="12" y2="23"></line><line x1="8" y1="23" x2="16" y2="23"></line></svg>;
const Volume2 = ({ size = 16 }) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><polygon points="11 5 6 9 2 9 2 15 6 15 11 19 11 5"></polygon><path d="M19.07 4.93a10 10 0 0 1 0 14.14M15.54 8.46a5 5 0 0 1 0 7.07"></path></svg>;
const VolumeX = () => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><polygon points="11 5 6 9 2 9 2 15 6 15 11 19 11 5"></polygon><line x1="23" y1="9" x2="17" y2="15"></line><line x1="17" y1="9" x2="23" y2="15"></line></svg>;
const MessageSquare = ({ size = 24 }) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"></path></svg>;
const Settings = ({ size = 20 }) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><circle cx="12" cy="12" r="3"></circle><path d="M12 1v6m0 6v6m9-9h-6m-6 0H3"></path></svg>;
const BookOpen = ({ size = 20 }) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M2 3h6a4 4 0 0 1 4 4v14a3 3 0 0 0-3-3H2z"></path><path d="M22 3h-6a4 4 0 0 0-4 4v14a3 3 0 0 1 3-3h7z"></path></svg>;
const Trophy = ({ size = 16 }) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M6 9H4.5a2.5 2.5 0 0 1 0-5H6"></path><path d="M18 9h1.5a2.5 2.5 0 0 0 0-5H18"></path><path d="M4 22h16"></path><path d="M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20.24 7 22"></path><path d="M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20.24 17 22"></path><path d="M18 2H6v7a6 6 0 0 0 12 0V2Z"></path></svg>;
const Target = ({ size = 16 }) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><circle cx="12" cy="12" r="10"></circle><circle cx="12" cy="12" r="6"></circle><circle cx="12" cy="12" r="2"></circle></svg>;
const RotateCcw = ({ size = 20 }) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><polyline points="1 4 1 10 7 10"></polyline><path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10"></path></svg>;
function FrenchTutor() {
const [messages, setMessages] = useState([]);
const [input, setInput] = useState('');
const [loading, setLoading] = useState(false);
const [level, setLevel] = useState('intermediate');
const [feedbackMode, setFeedbackMode] = useState('balanced');
const [showSettings, setShowSettings] = useState(false);
const [isListening, setIsListening] = useState(false);
const [autoSpeak, setAutoSpeak] = useState(true);
const [voiceSpeed, setVoiceSpeed] = useState(0.9);
const [currentMode, setCurrentMode] = useState('conversation');
const [vocabularyList, setVocabularyList] = useState([]);
const [showVocab, setShowVocab] = useState(false);
const [pronunciationScore, setPronunciationScore] = useState(null);
const messagesEndRef = useRef(null);
const recognitionRef = useRef(null);
const synthRef = useRef(window.speechSynthesis);
const conversationTopics = {
beginner: [
'Introducing yourself',
'Ordering food at a café',
'Asking for directions',
'Shopping for clothes',
'Talking about hobbies',
'Describing your family'
],
intermediate: [
'Planning a vacation',
'Discussing current events',
'Describing your job',
'Talking about movies and books',
'Health and wellness',
'French culture and traditions'
],
advanced: [
'Debating social issues',
'Discussing philosophy and ethics',
'Analyzing French literature',
'French politics and history',
'Business and professional topics',
'Idioms and expressions'
]
};
const scrollToBottom = () => {
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
};
useEffect(() => {
scrollToBottom();
}, [messages]);
useEffect(() => {
if (messages.length === 0) {
const welcomeMessage = {
role: 'assistant',
content: level === 'beginner'
? "Bonjour ! Je suis La Casseuse, votre tutrice de français. Hello! I'm La Casseuse, your French tutor. Choose a conversation topic or start speaking freely!"
: level === 'intermediate'
? "Bonjour ! Comment allez-vous ? Choose a topic or start a free conversation. I'll track your vocabulary and help with pronunciation."
: "Bonjour ! Ravi de vous rencontrer. Select a discussion topic or let's have a natural conversation. I'll help you master advanced French.",
timestamp: new Date().toISOString()
};
setMessages([welcomeMessage]);
if (autoSpeak) {
setTimeout(() => speak(welcomeMessage.content), 500);
}
}
}, [level]);
useEffect(() => {
if ('webkitSpeechRecognition' in window || 'SpeechRecognition' in window) {
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
recognitionRef.current = new SpeechRecognition();
recognitionRef.current.continuous = false;
recognitionRef.current.interimResults = false;
recognitionRef.current.lang = 'fr-FR';
recognitionRef.current.onresult = (event) => {
const transcript = event.results[0][0].transcript;
const confidence = event.results[0][0].confidence;
const score = Math.round(confidence * 100);
setPronunciationScore(score);
setInput(transcript);
setIsListening(false);
};
recognitionRef.current.onerror = (event) => {
console.error('Speech recognition error:', event.error);
setIsListening(false);
};
recognitionRef.current.onend = () => {
setIsListening(false);
};
}
return () => {
if (recognitionRef.current) {
recognitionRef.current.stop();
}
};
}, []);
const buildSystemPrompt = () => {
const levelDescriptions = {
beginner: 'A1-A2 level learner who is just starting with French. Use simple vocabulary and grammar. Provide translations for most French text. Be encouraging and patient.',
intermediate: 'B1-B2 level learner with basic French knowledge. Use more complex structures. Provide translations selectively. Challenge them while being supportive.',
advanced: 'C1-C2 level learner approaching fluency. Use natural, native-level French. Minimal translations. Focus on nuance, idioms, and cultural context.'
};
const feedbackDescriptions = {
minimal: 'Only correct major errors. Keep the conversation flowing naturally.',
balanced: 'Correct important errors and occasionally highlight good usage. Balance correction with encouragement.',
detailed: 'Provide thorough feedback on grammar, vocabulary choices, and pronunciation tips. Explain rules and alternatives.'
};
let basePrompt = `You are La Casseuse, an expert French language tutor having a conversation with a ${levelDescriptions[level]}
Feedback style: ${feedbackDescriptions[feedbackMode]}
Guidelines:
1. Respond naturally in French at the appropriate level
2. Keep responses conversational and relatively concise (2-4 sentences typically) since this is spoken conversation
3. When providing corrections, integrate them naturally
4. Use encouragement: "Très bien!", "Excellent!", "C'est ça!"`;
if (currentMode === 'vocabulary') {
basePrompt += `\n\nVOCABULARY MODE: At the end of your response, list 2-3 key vocabulary words or phrases from your message in this exact format:\nVOCAB: word1 (translation), word2 (translation), word3 (translation)`;
} else if (currentMode === 'pronunciation') {
basePrompt += `\n\nPRONUNCIATION MODE: Focus on helping them pronounce difficult words. When they make pronunciation errors, gently correct them and provide tips on French phonetics.`;
}
basePrompt += `\n\nFor beginners: Provide English translations in parentheses after French sentences.\nFor intermediate: Provide translations only for complex phrases or new vocabulary.\nFor advanced: Use French almost exclusively, with minimal English support.`;
return basePrompt;
};
const extractVocabulary = (text) => {
const vocabMatch = text.match(/VOCAB: (.+?)(?:\n|$)/);
if (vocabMatch) {
const vocabItems = vocabMatch[1].split(',').map(item => {
const parts = item.trim().match(/(.+?)\s*\((.+?)\)/);
if (parts) {
return { word: parts[1].trim(), translation: parts[2].trim() };
}
return null;
}).filter(Boolean);
setVocabularyList(prev => [...vocabItems, ...prev].slice(0, 30));
return text.replace(/VOCAB: .+?(?:\n|$)/, '').trim();
}
return text;
};
const handleSend = async (textToSend = input) => {
if (!textToSend.trim() || loading) return;
const userMessage = {
role: 'user',
content: textToSend,
timestamp: new Date().toISOString()
};
setMessages(prev => [...prev, userMessage]);
setInput('');
setLoading(true);
try {
const conversationHistory = [...messages, userMessage].map(msg => ({
role: msg.role,
content: msg.content
}));
// Call OUR backend instead of Claude directly
const response = await fetch('/api/chat', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'claude-sonnet-4-20250514',
max_tokens: 1000,
system: buildSystemPrompt(),
messages: conversationHistory
})
});
const data = await response.json();
if (data.content && data.content[0]) {
let content = data.content[0].text;
if (currentMode === 'vocabulary') {
content = extractVocabulary(content);
}
const assistantMessage = {
role: 'assistant',
content: content,
timestamp: new Date().toISOString()
};
setMessages(prev => [...prev, assistantMessage]);
if (autoSpeak) {
setTimeout(() => speak(assistantMessage.content), 300);
}
} else if (data.error) {
setMessages(prev => [...prev, {
role: 'assistant',
content: `Error: ${data.error}`,
timestamp: new Date().toISOString()
}]);
}
} catch (error) {
console.error('Error:', error);
setMessages(prev => [...prev, {
role: 'assistant',
content: 'Désolé, there was an error. Please try again.',
timestamp: new Date().toISOString()
}]);
} finally {
setLoading(false);
}
};
const speak = (text) => {
synthRef.current.cancel();
const cleanText = text.replace(/[✏️📚🗣️🇫🇷*]/g, '').replace(/\([^)]*\)/g, '');
const utterance = new SpeechSynthesisUtterance(cleanText);
utterance.lang = 'fr-FR';
utterance.rate = voiceSpeed;
const voices = synthRef.current.getVoices();
const frenchVoice = voices.find(voice => voice.lang.startsWith('fr'));
if (frenchVoice) {
utterance.voice = frenchVoice;
}
synthRef.current.speak(utterance);
};
const toggleListening = () => {
if (!recognitionRef.current) {
alert('Speech recognition is not supported in your browser. Please use Chrome, Edge, or Safari.');
return;
}
if (isListening) {
recognitionRef.current.stop();
setIsListening(false);
} else {
synthRef.current.cancel();
setInput('');
setPronunciationScore(null);
recognitionRef.current.start();
setIsListening(true);
}
};
const stopSpeaking = () => {
synthRef.current.cancel();
};
const startTopicConversation = async (topic) => {
const topicMessage = `Let's practice: ${topic}`;
setInput(topicMessage);
await handleSend(topicMessage);
};
const resetConversation = () => {
setMessages([]);
setVocabularyList([]);
setPronunciationScore(null);
const welcomeMessage = {
role: 'assistant',
content: "Bonjour ! Ready for a new conversation? Choose a topic or start speaking!",
timestamp: new Date().toISOString()
};
setMessages([welcomeMessage]);
if (autoSpeak) speak(welcomeMessage.content);
};
useEffect(() => {
if (input && !isListening) {
handleSend(input);
}
}, [input, isListening]);
const getPronunciationColor = (score) => {
if (score >= 80) return 'text-green-600';
if (score >= 60) return 'text-yellow-600';
return 'text-red-600';
};
const getPronunciationLabel = (score) => {
if (score >= 90) return 'Excellent!';
if (score >= 80) return 'Very Good';
if (score >= 70) return 'Good';
if (score >= 60) return 'Fair';
return 'Keep Practicing';
};
return (
<div className="flex flex-col h-screen bg-gradient-to-br from-blue-50 to-indigo-50">
{/* Header */}
<div className="bg-white shadow-sm border-b border-gray-200 px-6 py-4">
<div className="flex items-center justify-between max-w-6xl mx-auto">
<div className="flex items-center gap-3">
<div className="bg-blue-600 text-white p-2 rounded-lg">
<MessageSquare size={24} />
</div>
<div>
<h1 className="text-2xl font-bold text-gray-900">La Casseuse</h1>
<p className="text-sm text-gray-600">Your French conversation partner</p>
</div>
</div>
<div className="flex gap-2">
<button
onClick={() => setShowVocab(!showVocab)}
className={`p-2 rounded-lg transition-colors ${showVocab ? 'bg-blue-100 text-blue-600' : 'hover:bg-gray-100 text-gray-600'}`}
title="Vocabulary List"
>
<BookOpen size={20} />
{vocabularyList.length > 0 && (
</div>
</div>
))}
{loading && (
<div className="flex justify-start">
<div className="bg-white text-gray-900 shadow-sm border border-gray-200 rounded-2xl px-4 py-3">
<Loader2 />
</div>
</div>
)}
<div ref={messagesEndRef} />
</div>
</div>
</div>
{/* Voice Controls */}
<div className="bg-white border-t border-gray-200 px-4 py-6">
<div className="max-w-6xl mx-auto">
<div className="flex flex-col items-center gap-4">
{/* Microphone Button */}
<button
onClick={toggleListening}
disabled={loading}
className={`w-20 h-20 rounded-full flex items-center justify-center transition-all shadow-lg ${
isListening
? 'bg-red-500 hover:bg-red-600 animate-pulse'
: 'bg-blue-600 hover:bg-blue-700'
} text-white disabled:opacity-50 disabled:cursor-not-allowed`}
>
{isListening ? <MicOff /> : <Mic />}
</button>
{isListening && (
<div className="text-center">
<p className="text-sm font-medium text-gray-700">Listening...</p>
<p className="text-xs text-gray-500">Speak in French</p>
</div>
)}
{/* Text Input Alternative */}
<div className="w-full flex gap-2">
<input
type="text"
value={input}
onChange={(e) => setInput(e.target.value)}
onKeyPress={(e) => e.key === 'Enter' && handleSend()}
placeholder="Or type your message in French..."
className="flex-1 px-4 py-2 border border-gray-300 rounded-xl focus:ring-2 focus:ring-blue-500 focus:border-transparent text-sm"
disabled={loading || isListening}
/>
<button
onClick={() => handleSend()}
disabled={loading || !input.trim() || isListening}
className="bg-blue-600 text-white px-4 py-2 rounded-xl hover:bg-blue-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2"
>
{loading ? <Loader2 /> : <Send />}
</button>
<button
onClick={stopSpeaking}
className="bg-gray-600 text-white px-4 py-2 rounded-xl hover:bg-gray-700 transition-colors flex items-center gap-2"
title="Stop speaking"
>
<VolumeX />
</button>
</div>
<p className="text-xs text-gray-500 text-center">
Click microphone to speak • Choose topics from sidebar • {currentMode === 'vocabulary' && 'Building vocabulary list'}
</p>
</div>
</div>
</div>
</div>
);
}
ReactDOM.createRoot(document.getElementById('root')).render(<FrenchTutor />);
</script>
</body>
</html><span className="ml-1 text-xs font-bold">{vocabularyList.length}</span>
)}
</button>
<button
onClick={resetConversation}
className="p-2 hover:bg-gray-100 rounded-lg transition-colors text-gray-600"
title="New Conversation"
>
<RotateCcw size={20} />
</button>
<button
onClick={() => setShowSettings(!showSettings)}
className="p-2 hover:bg-gray-100 rounded-lg transition-colors text-gray-600"
>
<Settings size={20} />
</button>
</div>
</div>
</div>
{/* Mode Selector */}
<div className="bg-white border-b border-gray-200 px-6 py-3">
<div className="max-w-6xl mx-auto flex gap-2">
<button
onClick={() => setCurrentMode('conversation')}
className={`px-4 py-2 rounded-lg text-sm font-medium transition-colors ${
currentMode === 'conversation'
? 'bg-blue-600 text-white'
: 'bg-gray-100 text-gray-700 hover:bg-gray-200'
}`}
>
<MessageSquare size={16} style={{display: 'inline', marginRight: '4px'}} />
Free Talk
</button>
<button
onClick={() => setCurrentMode('vocabulary')}
className={`px-4 py-2 rounded-lg text-sm font-medium transition-colors ${
currentMode === 'vocabulary'
? 'bg-blue-600 text-white'
: 'bg-gray-100 text-gray-700 hover:bg-gray-200'
}`}
>
<BookOpen size={16} style={{display: 'inline', marginRight: '4px'}} />
Vocabulary Builder
</button>
<button
onClick={() => setCurrentMode('pronunciation')}
className={`px-4 py-2 rounded-lg text-sm font-medium transition-colors ${
currentMode === 'pronunciation'
? 'bg-blue-600 text-white'
: 'bg-gray-100 text-gray-700 hover:bg-gray-200'
}`}
>
Pronunciation Practice
</button>
</div>
</div>
{/* Settings Panel */}
{showSettings && (
<div className="bg-white border-b border-gray-200 px-6 py-4">
<div className="max-w-6xl mx-auto">
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
Proficiency Level
</label>
<select
value={level}
onChange={(e) => setLevel(e.target.value)}
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
>
<option value="beginner">Beginner (A1-A2)</option>
<option value="intermediate">Intermediate (B1-B2)</option>
<option value="advanced">Advanced (C1-C2)</option>
</select>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
Feedback Style
</label>
<select
value={feedbackMode}
onChange={(e) => setFeedbackMode(e.target.value)}
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
>
<option value="minimal">Minimal - Flow over accuracy</option>
<option value="balanced">Balanced - Mix of both</option>
<option value="detailed">Detailed - Maximum learning</option>
</select>
</div>
<div>
<label className="flex items-center gap-2">
<input
type="checkbox"
checked={autoSpeak}
onChange={(e) => setAutoSpeak(e.target.checked)}
className="w-4 h-4 text-blue-600 rounded"
/>
<span className="text-sm font-medium text-gray-700">
Auto-play responses
</span>
</label>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
Voice Speed: {voiceSpeed.toFixed(1)}x
</label>
<input
type="range"
min="0.5"
max="1.5"
step="0.1"
value={voiceSpeed}
onChange={(e) => setVoiceSpeed(parseFloat(e.target.value))}
className="w-full"
/>
</div>
</div>
</div>
</div>
)}
{/* Vocabulary Sidebar */}
{showVocab && (
<div className="bg-white border-b border-gray-200 px-6 py-4 max-h-64 overflow-y-auto">
<div className="max-w-6xl mx-auto">
<h3 className="text-lg font-bold text-gray-900 mb-3 flex items-center gap-2">
<BookOpen size={20} />
Your Vocabulary ({vocabularyList.length})
</h3>
{vocabularyList.length === 0 ? (
<p className="text-gray-500 text-sm">Start a vocabulary building session to collect new words!</p>
) : (
<div className="grid grid-cols-1 md:grid-cols-3 gap-2">
{vocabularyList.map((item, idx) => (
<div key={idx} className="bg-blue-50 rounded-lg p-2">
<p className="font-semibold text-blue-900">{item.word}</p>
<p className="text-sm text-gray-600">{item.translation}</p>
</div>
))}
</div>
)}
</div>
</div>
)}
<div className="flex-1 flex overflow-hidden">
{/* Topic Selector Sidebar */}
<div className="w-64 bg-white border-r border-gray-200 overflow-y-auto p-4">
<h3 className="text-sm font-bold text-gray-900 mb-3 flex items-center gap-2">
<Target size={16} />
Conversation Topics
</h3>
<div className="space-y-2">
{conversationTopics[level].map((topic, idx) => (
<button
key={idx}
onClick={() => startTopicConversation(topic)}
disabled={loading}
className="w-full text-left px-3 py-2 text-sm rounded-lg bg-gray-50 hover:bg-blue-50 hover:text-blue-700 transition-colors disabled:opacity-50"
>
{topic}
</button>
))}
</div>
{pronunciationScore !== null && (
<div className="mt-6 p-3 bg-gradient-to-br from-purple-50 to-pink-50 rounded-lg">
<div className="flex items-center gap-2 mb-2">
<Trophy size={16} />
<span className="text-sm font-bold text-gray-900">Last Score</span>
</div>
<div className={`text-3xl font-bold ${getPronunciationColor(pronunciationScore)}`}>
{pronunciationScore}%
</div>
<p className="text-xs text-gray-600 mt-1">{getPronunciationLabel(pronunciationScore)}</p>
</div>
)}
</div>
{/* Messages */}
<div className="flex-1 overflow-y-auto px-4 py-6">
<div className="max-w-4xl mx-auto space-y-4">
{messages.map((msg, idx) => (
<div
key={idx}
className={`flex ${msg.role === 'user' ? 'justify-end' : 'justify-start'}`}
>
<div
className={`max-w-2xl rounded-2xl px-4 py-3 ${
msg.role === 'user'
? 'bg-blue-600 text-white'
: 'bg-white text-gray-900 shadow-sm border border-gray-200'
}`}
>
<div className="flex items-start gap-2">
<div className="flex-1 whitespace-pre-wrap break-words">
{msg.content}
</div>
{msg.role === 'assistant' && (
<button
onClick={() => speak(msg.content)}
className="flex-shrink-0 p-1 hover:bg-gray-100 rounded transition-colors"
title="Listen"
>
<Volume2 size={16} />
</button>
)}
</div> |