mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
Fix redirect to record errors
This commit is contained in:
@@ -23,16 +23,20 @@ type TranscriptDetails = {
|
|||||||
export default function TranscriptDetails(details: TranscriptDetails) {
|
export default function TranscriptDetails(details: TranscriptDetails) {
|
||||||
const transcriptId = details.params.transcriptId;
|
const transcriptId = details.params.transcriptId;
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const statusToRedirect = ["idle", "recording", "processing"];
|
||||||
|
|
||||||
const transcript = useTranscript(transcriptId);
|
const transcript = useTranscript(transcriptId);
|
||||||
|
const transcriptStatus = transcript.response?.status;
|
||||||
|
const waiting =
|
||||||
|
!transcriptStatus || statusToRedirect.includes(transcriptStatus);
|
||||||
|
|
||||||
const topics = useTopics(transcriptId);
|
const topics = useTopics(transcriptId);
|
||||||
const waveform = useWaveform(transcriptId);
|
const waveform = useWaveform(transcriptId, waiting);
|
||||||
const useActiveTopic = useState<Topic | null>(null);
|
const useActiveTopic = useState<Topic | null>(null);
|
||||||
const mp3 = useMp3(transcriptId);
|
const mp3 = useMp3(transcriptId, waiting);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const statusToRedirect = ["idle", "recording", "processing"];
|
if (waiting) {
|
||||||
if (statusToRedirect.includes(transcript.response?.status || "")) {
|
|
||||||
const newUrl = "/transcripts/" + details.params.transcriptId + "/record";
|
const newUrl = "/transcripts/" + details.params.transcriptId + "/record";
|
||||||
// Shallow redirection does not work on NextJS 13
|
// Shallow redirection does not work on NextJS 13
|
||||||
// https://github.com/vercel/next.js/discussions/48110
|
// https://github.com/vercel/next.js/discussions/48110
|
||||||
@@ -40,7 +44,7 @@ export default function TranscriptDetails(details: TranscriptDetails) {
|
|||||||
router.replace(newUrl);
|
router.replace(newUrl);
|
||||||
// history.replaceState({}, "", newUrl);
|
// history.replaceState({}, "", newUrl);
|
||||||
}
|
}
|
||||||
}, [transcript.response?.status]);
|
}, [waiting]);
|
||||||
|
|
||||||
if (transcript.error || topics?.error) {
|
if (transcript.error || topics?.error) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ type AudioWaveFormResponse = {
|
|||||||
error: Error | null;
|
error: Error | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const useWaveform = (id: string): AudioWaveFormResponse => {
|
const useWaveform = (id: string, waiting: boolean): AudioWaveFormResponse => {
|
||||||
const [waveform, setWaveform] = useState<AudioWaveform | null>(null);
|
const [waveform, setWaveform] = useState<AudioWaveform | null>(null);
|
||||||
const [loading, setLoading] = useState<boolean>(true);
|
const [loading, setLoading] = useState<boolean>(true);
|
||||||
const [error, setErrorState] = useState<Error | null>(null);
|
const [error, setErrorState] = useState<Error | null>(null);
|
||||||
@@ -18,7 +18,7 @@ const useWaveform = (id: string): AudioWaveFormResponse => {
|
|||||||
const api = useApi();
|
const api = useApi();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!id || !api) return;
|
if (!id || !api || waiting) return;
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
api
|
api
|
||||||
.v1TranscriptGetAudioWaveform({ transcriptId: id })
|
.v1TranscriptGetAudioWaveform({ transcriptId: id })
|
||||||
@@ -36,7 +36,7 @@ const useWaveform = (id: string): AudioWaveFormResponse => {
|
|||||||
setError(err);
|
setError(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, [id, api]);
|
}, [id, api, waiting]);
|
||||||
|
|
||||||
return { waveform, loading, error };
|
return { waveform, loading, error };
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user