-
Notifications
You must be signed in to change notification settings - Fork 415
Transcript viewer final #1603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Transcript viewer final #1603
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3dd4c4c
disable regenerate when llm not available
yujonglee abe2ff4
disable pro banner for now
yujonglee c6b0c2c
better transcript rendering
yujonglee ee80150
autoscroll to bottom before first render
yujonglee 8c98a4f
fix am api
yujonglee 6fccf8f
add autoscroll
yujonglee 9185494
styling
yujonglee 580d1e2
mostly styling
yujonglee 0b619d3
fixes
yujonglee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 90 additions & 41 deletions
131
apps/desktop/src/components/main/body/sessions/note-input/transcript/viewer/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,54 +1,103 @@ | ||
| import { cn } from "@hypr/utils"; | ||
| import { type MaybePartialWord, useFinalWords, useMergedWordsByChannel, usePartialWords } from "./segment"; | ||
| import { DependencyList, useLayoutEffect, useRef } from "react"; | ||
| import { useSegments } from "./segment"; | ||
|
|
||
| export function TranscriptViewer({ sessionId }: { sessionId: string }) { | ||
| const finalWords = useFinalWords(sessionId); | ||
| const partialWords = usePartialWords(); | ||
| const wordsByChannel = useMergedWordsByChannel(finalWords, partialWords); | ||
|
|
||
| return <Renderer wordsByChannel={wordsByChannel} />; | ||
| const segments = useSegments(sessionId); | ||
| return <Renderer segments={segments} />; | ||
| } | ||
|
|
||
| function Renderer({ wordsByChannel }: { wordsByChannel: Map<number, MaybePartialWord[]> }) { | ||
| const channelIds = Array.from(wordsByChannel.keys()).sort((a, b) => a - b); | ||
| function Renderer({ segments }: { segments: ReturnType<typeof useSegments> }) { | ||
| const containerRef = useAutoScroll<HTMLDivElement>([segments]); | ||
|
|
||
| if (channelIds.length === 0) { | ||
| if (segments.length === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <div className="flex flex-col overflow-y-auto overflow-x-hidden max-h-[calc(100vh-250px)]"> | ||
| {channelIds.map((channelId) => { | ||
| const words = wordsByChannel.get(channelId) ?? []; | ||
| return ( | ||
| <div key={channelId} className="flex flex-col"> | ||
| <div | ||
| className={cn([ | ||
| "sticky top-0 z-10", | ||
| "py-2 px-3 -mx-3", | ||
| "bg-background", | ||
| "border-b border-border", | ||
| "text-sm font-semibold", | ||
| ])} | ||
| > | ||
| Channel {channelId} | ||
| </div> | ||
| <div className="text-sm leading-relaxed py-4 break-words overflow-wrap-anywhere"> | ||
| {words.map((word, idx) => ( | ||
| <span | ||
| key={`${word.start_ms}-${idx}`} | ||
| className={cn([ | ||
| !word.isFinal && ["opacity-60", "italic"], | ||
| ])} | ||
| > | ||
| {word.text} | ||
| {" "} | ||
| </span> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ); | ||
| })} | ||
| <div | ||
| ref={containerRef} | ||
| className={cn([ | ||
| "space-y-8 h-full overflow-y-auto overflow-x-hidden", | ||
| "px-0.5 pb-32 scroll-pb-[8rem]", | ||
| ])} | ||
| > | ||
| {segments.map( | ||
| (segment, i) => <Segment key={i} segment={segment} />, | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| function Segment({ segment }: { segment: ReturnType<typeof useSegments>[number] }) { | ||
| const timestamp = segment.words.length > 0 | ||
| ? `${formatTimestamp(segment.words[0].start_ms)} - ${ | ||
| formatTimestamp(segment.words[segment.words.length - 1].end_ms) | ||
| }` | ||
| : "00:00 - 00:00"; | ||
|
|
||
| return ( | ||
| <section> | ||
| <p | ||
| className={cn([ | ||
| "sticky top-0 z-20", | ||
| "-mx-3 px-3 py-1", | ||
| "bg-background", | ||
| "border-b border-neutral-200", | ||
| "text-neutral-500 text-xs font-light", | ||
| "flex items-center justify-between", | ||
| ])} | ||
| > | ||
| <span>Channel {segment.channel}</span> | ||
| <span className="font-mono">{timestamp}</span> | ||
| </p> | ||
|
|
||
| <div className="mt-1.5 text-sm leading-relaxed break-words overflow-wrap-anywhere"> | ||
| {segment.words.map((word, idx) => ( | ||
| <span | ||
| key={`${word.start_ms}-${idx}`} | ||
| className={cn([ | ||
| !word.isFinal && ["opacity-60", "italic"], | ||
| ])} | ||
| > | ||
| {word.text} | ||
| {" "} | ||
| </span> | ||
| ))} | ||
| </div> | ||
| </section> | ||
| ); | ||
| } | ||
|
|
||
| function useAutoScroll<T extends HTMLElement>(deps: DependencyList) { | ||
| const ref = useRef<T | null>(null); | ||
|
|
||
| useLayoutEffect(() => { | ||
| const element = ref.current; | ||
| if (!element) { | ||
| return; | ||
| } | ||
|
|
||
| const isAtTop = element.scrollTop === 0; | ||
| const isNearBottom = element.scrollHeight - element.scrollTop - element.clientHeight < 100; | ||
|
|
||
| if (isAtTop || isNearBottom) { | ||
| element.scrollTop = element.scrollHeight; | ||
| } | ||
| }, deps); | ||
|
|
||
| return ref; | ||
| } | ||
|
|
||
| function formatTimestamp(ms: number): string { | ||
| const totalSeconds = Math.floor(ms / 1000); | ||
| const hours = Math.floor(totalSeconds / 3600); | ||
| const minutes = Math.floor((totalSeconds % 3600) / 60); | ||
| const seconds = totalSeconds % 60; | ||
|
|
||
| if (hours > 0) { | ||
| return `${hours}:${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`; | ||
| } | ||
|
|
||
| return `${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.