Skip to content
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

fix: scroll lock in transcriptions #34

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export class DyteAiTranscriptions {
/** Initial transcriptions */
@Prop() initialTranscriptions: Transcript[];

private autoScrollEnabled = true;

// private transcriptionHandler(data: Transcript) {
// this.transcriptions = [...this.transcriptions, data];
// }
Expand All @@ -54,10 +56,13 @@ export class DyteAiTranscriptions {
if (!this.meeting) return;

this.meetingChanged(this.meeting);

this.contentContainer?.addEventListener('scroll', this.onScroll);
}

disconnectedCallback() {
this.meeting?.ai?.off('transcript', this.onTranscriptHandler);
this.contentContainer?.removeEventListener('scroll', this.onScroll);
}

@Watch('meeting')
Expand All @@ -70,16 +75,31 @@ export class DyteAiTranscriptions {

@Watch('transcriptions')
transcriptionsChanged() {
setTimeout(() => {
smoothScrollToBottom(this.contentContainer, false);
}, 100);
if (this.autoScrollEnabled) {
setTimeout(() => {
smoothScrollToBottom(this.contentContainer, false);
}, 100);
}
}

private onScroll = (e: Event) => {
const { scrollTop, clientHeight, scrollHeight } = e.target as HTMLDivElement;
const fromTop = scrollTop + clientHeight;

if (fromTop + 10 >= scrollHeight) {
// at bottom
this.autoScrollEnabled = true;
} else {
// not at bottom
this.autoScrollEnabled = false;
}
};

private onTranscriptHandler = (data: Transcript) => {
this.transcriptions = this.transcriptionsReducer(this.transcriptions, data);
};

renderTranscripts() {
private renderTranscripts() {
const transcripts = this.transcriptions.filter((t) =>
this.participantQuery
? t.name.toLowerCase().includes(this.participantQuery.toLowerCase())
Expand Down
Loading