better mp3 absense handling on transcription page

This commit is contained in:
Igor Loskutov
2025-06-18 23:40:22 -04:00
parent 49f4b65f47
commit 98acf298d6
3 changed files with 20 additions and 12 deletions

View File

@@ -54,15 +54,6 @@ export default function TranscriptDetails(details: TranscriptDetails) {
); );
} }
if (mp3.audioDeleted) {
return (
<Modal
title="Can't find transcription: Transcription file is deleted"
text={`The recording is deleted.`}
/>
);
}
if (transcript?.loading || topics?.loading) { if (transcript?.loading || topics?.loading) {
return <Modal title="Loading" text={"Loading transcript..."} />; return <Modal title="Loading" text={"Loading transcript..."} />;
} }
@@ -87,7 +78,7 @@ export default function TranscriptDetails(details: TranscriptDetails) {
mt={4} mt={4}
mb={4} mb={4}
> >
{waveform.waveform && mp3.media && topics.topics ? ( {waveform.waveform && mp3.media && !mp3.audioDeleted && topics.topics ? (
<Player <Player
topics={topics?.topics} topics={topics?.topics}
useActiveTopic={useActiveTopic} useActiveTopic={useActiveTopic}
@@ -97,6 +88,8 @@ export default function TranscriptDetails(details: TranscriptDetails) {
/> />
) : waveform.error ? ( ) : waveform.error ? (
<div>"error loading this recording"</div> <div>"error loading this recording"</div>
) : mp3.audioDeleted ? (
<div>Audio was deleted</div>
) : ( ) : (
<Skeleton h={14} /> <Skeleton h={14} />
)} )}

View File

@@ -8,7 +8,6 @@ import "../../../../styles/button.css";
import { Topic } from "../../webSocketTypes"; import { Topic } from "../../webSocketTypes";
import { lockWakeState, releaseWakeState } from "../../../../lib/wakeLock"; import { lockWakeState, releaseWakeState } from "../../../../lib/wakeLock";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import Player from "../../player";
import useMp3 from "../../useMp3"; import useMp3 from "../../useMp3";
import WaveformLoading from "../../waveformLoading"; import WaveformLoading from "../../waveformLoading";
import { Box, Text, Grid, Heading, VStack, Flex } from "@chakra-ui/react"; import { Box, Text, Grid, Heading, VStack, Flex } from "@chakra-ui/react";

View File

@@ -47,9 +47,11 @@ const useMp3 = (transcriptId: string, waiting?: boolean): Mp3Response => {
}); });
}, [navigator.serviceWorker, !serviceWorker, accessTokenInfo]); }, [navigator.serviceWorker, !serviceWorker, accessTokenInfo]);
useEffect(() => { useEffect(() => {
if (!transcriptId || !api || later) return; if (!transcriptId || !api || later) return;
let deleted: boolean | null = null;
setTranscriptMetadataLoading(true); setTranscriptMetadataLoading(true);
@@ -59,12 +61,20 @@ const useMp3 = (transcriptId: string, waiting?: boolean): Mp3Response => {
audioElement.preload = "auto"; audioElement.preload = "auto";
const handleCanPlay = () => { const handleCanPlay = () => {
if (deleted) {
console.error('Illegal state: audio supposed to be deleted, but was loaded');
return;
}
setAudioLoading(false); setAudioLoading(false);
setAudioLoadingError(null); setAudioLoadingError(null);
}; };
const handleError = () => { const handleError = () => {
setAudioLoading(false); setAudioLoading(false);
if (deleted) {
// we arrived here earlier, ignore
return;
}
setAudioLoadingError("Failed to load audio"); setAudioLoadingError("Failed to load audio");
}; };
@@ -81,8 +91,14 @@ const useMp3 = (transcriptId: string, waiting?: boolean): Mp3Response => {
api.v1TranscriptGet({ transcriptId }) api.v1TranscriptGet({ transcriptId })
.then((transcript) => { .then((transcript) => {
if (stopped) return; if (stopped) return;
setAudioDeleted(transcript.audio_deleted || false); deleted = transcript.audio_deleted || false;
setAudioDeleted(deleted);
setTranscriptMetadataLoadingError(null); setTranscriptMetadataLoadingError(null);
if (deleted) {
setMedia(null);
setAudioLoadingError(null);
}
// if deleted, media will or already returned error
}) })
.catch((error) => { .catch((error) => {
if (stopped) return; if (stopped) return;