Skip to content

Commit 8602f88

Browse files
committed
Move to next talk on the STT automatically
1 parent 53eb7c5 commit 8602f88

3 files changed

Lines changed: 38 additions & 26 deletions

File tree

src/public/transcription/TranscriptionApp.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { useLocalStorage } from '@uidotdev/usehooks'
22
import { Box, Button, Container, TextField, Typography } from '@mui/material'
3-
import { useState } from 'react'
3+
import { useCallback, useState } from 'react'
44
import { usePasswordProtectedEvent } from '../hooks/usePasswordProtectedEvent'
55
import { useTalkSelection } from './useTalkSelection'
6-
import { useAutoReloadAfterTalk } from './useAutoReloadAfterTalk'
6+
import { useAutoAdvanceAfterTalk } from './useAutoAdvanceAfterTalk'
77
import { LiveTranscriptionView } from './LiveTranscriptionView'
88
import { DateTime } from 'luxon'
99

@@ -21,8 +21,15 @@ export const TranscriptionApp = ({ eventId }: PublicEventTranscriptionProps) =>
2121

2222
const [selectedTalk, upcomingTalks, resetSelectedTalk, setSelectedTalk] = useTalkSelection(selectedTrack, eventData)
2323

24-
// Roll the screen over automatically 5 min after the current talk ends.
25-
useAutoReloadAfterTalk(selectedTalk?.dateEnd)
24+
const advanceToNextTalk = useCallback(() => {
25+
if (!selectedTalk) return
26+
const currentIndex = upcomingTalks.findIndex((t) => t.id === selectedTalk.id)
27+
const next = upcomingTalks[currentIndex + 1]
28+
if (next) setSelectedTalk(next)
29+
}, [selectedTalk, upcomingTalks, setSelectedTalk])
30+
31+
// Roll over to the next talk automatically 5 min after the current one ends.
32+
useAutoAdvanceAfterTalk(selectedTalk?.dateEnd, advanceToNextTalk)
2633

2734
const saveStuffInLocalStorage = (pagePassword: string, selectedTrack: string) => {
2835
setSelectedTrack(selectedTrack)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { useEffect } from 'react'
2+
import { DateTime } from 'luxon'
3+
4+
const ADVANCE_DELAY_MS = 5 * 60 * 1000
5+
// setTimeout delays above 2^31-1 ms overflow and fire immediately — ignore anything that far out.
6+
const MAX_TIMEOUT_MS = 2 ** 31 - 1
7+
8+
// Advances to the next talk 5 minutes after the current one ends, so the caption screen rolls over
9+
// without anyone touching the machine.
10+
export const useAutoAdvanceAfterTalk = (talkEndIso: string | undefined, onAdvance: () => void) => {
11+
useEffect(() => {
12+
if (!talkEndIso) return
13+
const end = DateTime.fromISO(talkEndIso)
14+
if (!end.isValid) return
15+
16+
const delay = end.toMillis() + ADVANCE_DELAY_MS - DateTime.now().toMillis()
17+
if (delay > MAX_TIMEOUT_MS) return
18+
19+
if (delay <= 0) {
20+
onAdvance()
21+
return
22+
}
23+
24+
const timer = setTimeout(onAdvance, delay)
25+
return () => clearTimeout(timer)
26+
}, [talkEndIso, onAdvance])
27+
}

src/public/transcription/useAutoReloadAfterTalk.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)