Yassine Mhirsi commited on
Commit
28269c5
·
1 Parent(s): 15bddd3

transcript toggle

Browse files
src/app/components/chat/MessageList.tsx CHANGED
@@ -2,6 +2,7 @@ import React, { useEffect, useRef } from 'react';
2
  import type { ChatMessage } from '../../types/chat.types.ts';
3
  import { Loader2, AlertCircle, RotateCcw } from 'lucide-react';
4
  import AudioPlayer from './AudioPlayer.tsx';
 
5
 
6
  type MessageListProps = {
7
  messages: ChatMessage[];
@@ -61,15 +62,12 @@ const MessageList = ({ messages, isLoading = false, error = null, onRetry }: Mes
61
  }`}
62
  >
63
  {message.audioUrl ? (
64
- // Audio message display - show both audio player and text
65
  <div>
66
  <AudioPlayer
67
  src={message.audioUrl}
68
  />
69
- {/* Display the text content under the audio player */}
70
- <div className="mt-2 whitespace-pre-wrap break-words">
71
- {message.content}
72
- </div>
73
  </div>
74
  ) : (
75
  // Regular text message
 
2
  import type { ChatMessage } from '../../types/chat.types.ts';
3
  import { Loader2, AlertCircle, RotateCcw } from 'lucide-react';
4
  import AudioPlayer from './AudioPlayer.tsx';
5
+ import TranscriptToggle from './TranscriptToggle.tsx';
6
 
7
  type MessageListProps = {
8
  messages: ChatMessage[];
 
62
  }`}
63
  >
64
  {message.audioUrl ? (
65
+ // Audio message display with toggleable text transcript
66
  <div>
67
  <AudioPlayer
68
  src={message.audioUrl}
69
  />
70
+ <TranscriptToggle content={message.content} />
 
 
 
71
  </div>
72
  ) : (
73
  // Regular text message
src/app/components/chat/TranscriptToggle.tsx ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React, { useState } from 'react';
2
+ import { ChevronDown, ChevronUp } from 'lucide-react';
3
+
4
+ type TranscriptToggleProps = {
5
+ content: string;
6
+ };
7
+
8
+ const TranscriptToggle: React.FC<TranscriptToggleProps> = ({ content }) => {
9
+ const [isExpanded, setIsExpanded] = useState(false);
10
+
11
+ const toggleTranscript = () => {
12
+ setIsExpanded(!isExpanded);
13
+ };
14
+
15
+ return (
16
+ <div className="mt-3">
17
+ <button
18
+ onClick={toggleTranscript}
19
+ className="flex items-center space-x-1 text-sm text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 transition-colors focus:outline-none focus:ring-2 focus:ring-teal-500 rounded"
20
+ aria-expanded={isExpanded}
21
+ aria-label={isExpanded ? "Hide transcript" : "Show transcript"}
22
+ >
23
+ <span>{isExpanded ? "Hide transcript" : "Show transcript"}</span>
24
+ {isExpanded ? (
25
+ <ChevronUp className="w-4 h-4" />
26
+ ) : (
27
+ <ChevronDown className="w-4 h-4" />
28
+ )}
29
+ </button>
30
+ {isExpanded && (
31
+ <div
32
+ className="mt-2 pt-2 border-t border-gray-200 dark:border-gray-700 whitespace-pre-wrap break-words text-gray-800 dark:text-gray-200"
33
+ >
34
+ {content}
35
+ </div>
36
+ )}
37
+ </div>
38
+ );
39
+ };
40
+
41
+ export default TranscriptToggle;