mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-03 14:34:40 +00:00
fix(video): refine transcript viewing and generation
This commit is contained in:
@@ -164,6 +164,7 @@ export function FileBrowser({
|
||||
const [contextMenuItem, setContextMenuItem] = useState<AssetInfo | null>(null)
|
||||
const [similarImage, setSimilarImage] = useState<AssetInfo | null>(null)
|
||||
const [transcriptVideo, setTranscriptVideo] = useState<{ id: string; name: string } | null>(null)
|
||||
const closeTranscriptDialog = useCallback(() => setTranscriptVideo(null), [])
|
||||
const transcriptionEnabled = useServerFeatures().data?.transcriptionEnabled
|
||||
const semanticSearchEnabled = useSemanticSearchEnabled(
|
||||
teamId,
|
||||
@@ -1196,7 +1197,7 @@ export function FileBrowser({
|
||||
key={transcriptVideo.id}
|
||||
assetId={transcriptVideo.id}
|
||||
name={transcriptVideo.name}
|
||||
onClose={() => setTranscriptVideo(null)}
|
||||
onClose={closeTranscriptDialog}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ export function GenerateTranscriptsDialog({
|
||||
onClose: () => void
|
||||
}) {
|
||||
const dialogRef = useRef<HTMLDivElement>(null)
|
||||
const activeTaskId = useRef<string>(undefined)
|
||||
const queryClient = useQueryClient()
|
||||
const [language, setLanguage] = useState('')
|
||||
const param = { fileId: assetId }
|
||||
@@ -79,12 +80,24 @@ export function GenerateTranscriptsDialog({
|
||||
},
|
||||
refetchInterval: (query) => (isActive(query.state.data) ? 2_000 : false),
|
||||
})
|
||||
const hasFreshJobStatus = job.isFetchedAfterMount && job.isSuccess
|
||||
|
||||
useEffect(() => {
|
||||
if (job.data?.status === 'completed') {
|
||||
void queryClient.invalidateQueries({ queryKey: savedTranscriptLanguagesKey(assetId) })
|
||||
if (!job.data) return
|
||||
if (isActive(job.data)) {
|
||||
// Reopening the dialog can briefly show a cached status for a finished job.
|
||||
if (hasFreshJobStatus) activeTaskId.current = job.data.taskId
|
||||
return
|
||||
}
|
||||
}, [assetId, job.data, queryClient])
|
||||
if (job.data.status !== 'completed') return
|
||||
|
||||
void queryClient.invalidateQueries({ queryKey: savedTranscriptLanguagesKey(assetId) })
|
||||
if (activeTaskId.current === job.data.taskId) {
|
||||
activeTaskId.current = undefined
|
||||
toast.success(m.transcript_completed())
|
||||
onClose()
|
||||
}
|
||||
}, [assetId, hasFreshJobStatus, job.data, onClose, queryClient])
|
||||
|
||||
const generate = useMutation({
|
||||
mutationFn: async () => {
|
||||
@@ -105,6 +118,7 @@ export function GenerateTranscriptsDialog({
|
||||
)
|
||||
return
|
||||
}
|
||||
activeTaskId.current = result.taskId
|
||||
queryClient.setQueryData<TranscriptJobStatus>(statusKey, {
|
||||
status: 'pending',
|
||||
taskId: result.taskId,
|
||||
|
||||
@@ -74,10 +74,7 @@ const SegmentRow = memo(function SegmentRow({
|
||||
<button
|
||||
type="button"
|
||||
aria-current={active ? 'true' : undefined}
|
||||
className={cn(
|
||||
'block w-full cursor-pointer select-text rounded-md px-3 py-2 text-start hover:bg-accent focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring focus-visible:outline-none',
|
||||
active && 'bg-primary/10 font-medium text-foreground',
|
||||
)}
|
||||
className="block w-full cursor-pointer select-text rounded-md px-3 py-2 text-start hover:bg-accent focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring focus-visible:outline-none"
|
||||
onClick={(event) => {
|
||||
const selection = window.getSelection()
|
||||
if (
|
||||
@@ -95,7 +92,10 @@ const SegmentRow = memo(function SegmentRow({
|
||||
{formatTranscriptTime(segment.startMs)} – {formatTranscriptTime(segment.endMs)}
|
||||
</span>
|
||||
<span
|
||||
className="block text-sm leading-relaxed whitespace-pre-wrap wrap-anywhere"
|
||||
className={cn(
|
||||
'block text-sm leading-relaxed whitespace-pre-wrap wrap-anywhere',
|
||||
active && 'font-bold text-primary',
|
||||
)}
|
||||
dir="auto"
|
||||
>
|
||||
{matches?.map((match) => {
|
||||
@@ -108,7 +108,7 @@ const SegmentRow = memo(function SegmentRow({
|
||||
<mark
|
||||
data-current-match={selected ? '' : undefined}
|
||||
className={cn(
|
||||
'rounded-sm bg-primary/15 text-foreground',
|
||||
'rounded-sm bg-primary/15 px-px text-foreground',
|
||||
selected && 'bg-primary text-primary-foreground',
|
||||
)}
|
||||
>
|
||||
|
||||
@@ -19,7 +19,7 @@ export function TranscriptToggleButton({
|
||||
aria-controls={open ? panelId : undefined}
|
||||
title={m.transcript_view()}
|
||||
className={cn(
|
||||
'shrink-0 rounded transition-colors hover:text-primary focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none',
|
||||
'shrink-0 cursor-pointer rounded transition-colors hover:text-primary focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none',
|
||||
open && 'text-primary',
|
||||
className,
|
||||
)}
|
||||
|
||||
@@ -863,7 +863,7 @@ function FileViewPage() {
|
||||
key={transcript.panel.assetId}
|
||||
{...transcript.panel}
|
||||
mediaControllerRef={mediaControllerRef}
|
||||
className="w-[clamp(16rem,26vw,22rem)] max-w-[48%] border-r border-border"
|
||||
className="w-[30vw] max-w-[48%] border-r border-border"
|
||||
/>
|
||||
)}
|
||||
<div className={transcript?.panel ? 'hidden' : 'contents'}>
|
||||
|
||||
Reference in New Issue
Block a user