Commit
Restyle transcript with auto-scroll
commit
bb71c6e
1 changed file with +20 and −11
modified client/src/components/Transcript.tsx +20 −11
| @@ -1,22 +1,31 @@ | ||
| 1 | +import { useEffect, useRef } from 'react' | |
| 1 | 2 | import type { Segment } from 'shared/types' |
| 2 | 3 | |
| 3 | 4 | interface TranscriptProps { |
| 4 | 5 | segments: Segment[] |
| 5 | 6 | } |
| 6 | 7 | |
| 7 | 8 | export function Transcript({ segments }: TranscriptProps) { |
| 8 | - if (segments.length === 0) { | |
| 9 | - return <p className="transcript-empty">No answers yet. Say or type what you want to build.</p> | |
| 10 | - } | |
| 9 | + const listRef = useRef<HTMLDivElement>(null) | |
| 10 | + | |
| 11 | + useEffect(() => { | |
| 12 | + const list = listRef.current | |
| 13 | + if (list) list.scrollTop = list.scrollHeight | |
| 14 | + }, [segments.length]) | |
| 15 | + | |
| 16 | + if (segments.length === 0) return null | |
| 11 | 17 | |
| 12 | 18 | return ( |
| 13 | - <div className="transcript"> | |
| 14 | - {segments.map((segment) => ( | |
| 15 | - <div key={segment.id} className={`segment segment-${segment.speaker}`}> | |
| 16 | - <span className="segment-speaker">{segment.speaker === 'user' ? 'You' : 'Interviewer'}</span> | |
| 17 | - <p className="segment-text">{segment.text}</p> | |
| 18 | - </div> | |
| 19 | - ))} | |
| 20 | - </div> | |
| 19 | + <section className="transcript-section"> | |
| 20 | + <h2 className="transcript-title">Transcript</h2> | |
| 21 | + <div ref={listRef} className="transcript"> | |
| 22 | + {segments.map((segment) => ( | |
| 23 | + <div key={segment.id} className={`segment segment-${segment.speaker}`}> | |
| 24 | + <span className="segment-speaker">{segment.speaker === 'user' ? 'You' : 'Interviewer'}</span> | |
| 25 | + <p className="segment-text">{segment.text}</p> | |
| 26 | + </div> | |
| 27 | + ))} | |
| 28 | + </div> | |
| 29 | + </section> | |
| 21 | 30 | ) |
| 22 | 31 | } |