mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-23 05:39:05 +00:00
feat: complete migration from @hey-api/openapi-ts to openapi-react-query
- Migrated all components from useApi compatibility layer to direct React Query hooks - Added new hooks for participant operations, room meetings, and speaker operations - Updated all imports from old api module to api-types - Fixed TypeScript types and API endpoint signatures - Removed deprecated useApi.ts compatibility layer - Fixed SourceKind enum values to match OpenAPI spec - Added @ts-ignore for Zulip endpoints not in OpenAPI spec yet - Fixed all compilation errors and type issues
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { useContext, useEffect, useState } from "react";
|
||||
import { DomainContext } from "../../domainContext";
|
||||
import getApi from "../../lib/useApi";
|
||||
import { useTranscriptGet } from "../../lib/api-hooks";
|
||||
import { useSession } from "next-auth/react";
|
||||
|
||||
export type Mp3Response = {
|
||||
media: HTMLMediaElement | null;
|
||||
@@ -17,14 +18,17 @@ const useMp3 = (transcriptId: string, waiting?: boolean): Mp3Response => {
|
||||
const [audioLoadingError, setAudioLoadingError] = useState<null | string>(
|
||||
null,
|
||||
);
|
||||
const [transcriptMetadataLoading, setTranscriptMetadataLoading] =
|
||||
useState<boolean>(true);
|
||||
const [transcriptMetadataLoadingError, setTranscriptMetadataLoadingError] =
|
||||
useState<string | null>(null);
|
||||
const [audioDeleted, setAudioDeleted] = useState<boolean | null>(null);
|
||||
const api = getApi();
|
||||
const { api_url } = useContext(DomainContext);
|
||||
const accessTokenInfo = api?.httpRequest?.config?.TOKEN;
|
||||
const { data: session } = useSession();
|
||||
const accessTokenInfo = (session as any)?.accessToken as string | undefined;
|
||||
|
||||
// Use React Query to fetch transcript metadata
|
||||
const {
|
||||
data: transcript,
|
||||
isLoading: transcriptMetadataLoading,
|
||||
error: transcriptError,
|
||||
} = useTranscriptGet(later ? null : transcriptId);
|
||||
|
||||
const [serviceWorker, setServiceWorker] =
|
||||
useState<ServiceWorkerRegistration | null>(null);
|
||||
@@ -52,72 +56,50 @@ const useMp3 = (transcriptId: string, waiting?: boolean): Mp3Response => {
|
||||
}, [navigator.serviceWorker, !serviceWorker, accessTokenInfo]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!transcriptId || !api || later) return;
|
||||
if (!transcriptId || later || !transcript) return;
|
||||
|
||||
let stopped = false;
|
||||
let audioElement: HTMLAudioElement | null = null;
|
||||
let handleCanPlay: (() => void) | null = null;
|
||||
let handleError: (() => void) | null = null;
|
||||
|
||||
setTranscriptMetadataLoading(true);
|
||||
setAudioLoading(true);
|
||||
|
||||
// First fetch transcript info to check if audio is deleted
|
||||
api
|
||||
.v1TranscriptGet({ transcriptId })
|
||||
.then((transcript) => {
|
||||
if (stopped) {
|
||||
return;
|
||||
}
|
||||
const deleted = transcript.audio_deleted || false;
|
||||
setAudioDeleted(deleted);
|
||||
|
||||
const deleted = transcript.audio_deleted || false;
|
||||
setAudioDeleted(deleted);
|
||||
setTranscriptMetadataLoadingError(null);
|
||||
if (deleted) {
|
||||
// Audio is deleted, don't attempt to load it
|
||||
setMedia(null);
|
||||
setAudioLoadingError(null);
|
||||
setAudioLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (deleted) {
|
||||
// Audio is deleted, don't attempt to load it
|
||||
setMedia(null);
|
||||
setAudioLoadingError(null);
|
||||
setAudioLoading(false);
|
||||
return;
|
||||
}
|
||||
// Audio is not deleted, proceed to load it
|
||||
audioElement = document.createElement("audio");
|
||||
audioElement.src = `${api_url}/v1/transcripts/${transcriptId}/audio/mp3`;
|
||||
audioElement.crossOrigin = "anonymous";
|
||||
audioElement.preload = "auto";
|
||||
|
||||
// Audio is not deleted, proceed to load it
|
||||
audioElement = document.createElement("audio");
|
||||
audioElement.src = `${api_url}/v1/transcripts/${transcriptId}/audio/mp3`;
|
||||
audioElement.crossOrigin = "anonymous";
|
||||
audioElement.preload = "auto";
|
||||
handleCanPlay = () => {
|
||||
if (stopped) return;
|
||||
setAudioLoading(false);
|
||||
setAudioLoadingError(null);
|
||||
};
|
||||
|
||||
handleCanPlay = () => {
|
||||
if (stopped) return;
|
||||
setAudioLoading(false);
|
||||
setAudioLoadingError(null);
|
||||
};
|
||||
handleError = () => {
|
||||
if (stopped) return;
|
||||
setAudioLoading(false);
|
||||
setAudioLoadingError("Failed to load audio");
|
||||
};
|
||||
|
||||
handleError = () => {
|
||||
if (stopped) return;
|
||||
setAudioLoading(false);
|
||||
setAudioLoadingError("Failed to load audio");
|
||||
};
|
||||
audioElement.addEventListener("canplay", handleCanPlay);
|
||||
audioElement.addEventListener("error", handleError);
|
||||
|
||||
audioElement.addEventListener("canplay", handleCanPlay);
|
||||
audioElement.addEventListener("error", handleError);
|
||||
|
||||
if (!stopped) {
|
||||
setMedia(audioElement);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
if (stopped) return;
|
||||
console.error("Failed to fetch transcript:", error);
|
||||
setAudioDeleted(null);
|
||||
setTranscriptMetadataLoadingError(error.message);
|
||||
setAudioLoading(false);
|
||||
})
|
||||
.finally(() => {
|
||||
if (stopped) return;
|
||||
setTranscriptMetadataLoading(false);
|
||||
});
|
||||
if (!stopped) {
|
||||
setMedia(audioElement);
|
||||
}
|
||||
|
||||
return () => {
|
||||
stopped = true;
|
||||
@@ -128,14 +110,18 @@ const useMp3 = (transcriptId: string, waiting?: boolean): Mp3Response => {
|
||||
if (handleError) audioElement.removeEventListener("error", handleError);
|
||||
}
|
||||
};
|
||||
}, [transcriptId, api, later, api_url]);
|
||||
}, [transcriptId, transcript, later, api_url]);
|
||||
|
||||
const getNow = () => {
|
||||
setLater(false);
|
||||
};
|
||||
|
||||
const loading = audioLoading || transcriptMetadataLoading;
|
||||
const error = audioLoadingError || transcriptMetadataLoadingError;
|
||||
const error =
|
||||
audioLoadingError ||
|
||||
(transcriptError
|
||||
? (transcriptError as any).message || String(transcriptError)
|
||||
: null);
|
||||
|
||||
return { media, loading, error, getNow, audioDeleted };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user