mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +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 React, { useState } from "react";
|
||||
import useApi from "../../lib/useApi";
|
||||
import { useTranscriptUploadAudio } from "../../lib/api-hooks";
|
||||
import { Button, Spinner } from "@chakra-ui/react";
|
||||
import { useError } from "../../(errors)/errorContext";
|
||||
|
||||
type FileUploadButton = {
|
||||
transcriptId: string;
|
||||
@@ -8,13 +9,16 @@ type FileUploadButton = {
|
||||
|
||||
export default function FileUploadButton(props: FileUploadButton) {
|
||||
const fileInputRef = React.useRef<HTMLInputElement>(null);
|
||||
const api = useApi();
|
||||
const uploadMutation = useTranscriptUploadAudio();
|
||||
const { setError } = useError();
|
||||
const [progress, setProgress] = useState(0);
|
||||
const triggerFileUpload = () => {
|
||||
fileInputRef.current?.click();
|
||||
};
|
||||
|
||||
const handleFileUpload = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const handleFileUpload = async (
|
||||
event: React.ChangeEvent<HTMLInputElement>,
|
||||
) => {
|
||||
const file = event.target.files?.[0];
|
||||
|
||||
if (file) {
|
||||
@@ -24,37 +28,45 @@ export default function FileUploadButton(props: FileUploadButton) {
|
||||
let start = 0;
|
||||
let uploadedSize = 0;
|
||||
|
||||
api?.httpRequest.config.interceptors.request.use((request) => {
|
||||
request.onUploadProgress = (progressEvent) => {
|
||||
const currentProgress = Math.floor(
|
||||
((uploadedSize + progressEvent.loaded) / file.size) * 100,
|
||||
);
|
||||
setProgress(currentProgress);
|
||||
};
|
||||
return request;
|
||||
});
|
||||
|
||||
const uploadNextChunk = async () => {
|
||||
if (chunkNumber == totalChunks) return;
|
||||
if (chunkNumber == totalChunks) {
|
||||
setProgress(0);
|
||||
return;
|
||||
}
|
||||
|
||||
const chunkSize = Math.min(maxChunkSize, file.size - start);
|
||||
const end = start + chunkSize;
|
||||
const chunk = file.slice(start, end);
|
||||
|
||||
await api?.v1TranscriptRecordUpload({
|
||||
transcriptId: props.transcriptId,
|
||||
formData: {
|
||||
chunk,
|
||||
},
|
||||
chunkNumber,
|
||||
totalChunks,
|
||||
});
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append("chunk", chunk);
|
||||
|
||||
uploadedSize += chunkSize;
|
||||
chunkNumber++;
|
||||
start = end;
|
||||
await uploadMutation.mutateAsync({
|
||||
params: {
|
||||
path: {
|
||||
transcript_id: props.transcriptId,
|
||||
},
|
||||
query: {
|
||||
chunk_number: chunkNumber,
|
||||
total_chunks: totalChunks,
|
||||
},
|
||||
},
|
||||
body: formData as any,
|
||||
});
|
||||
|
||||
uploadNextChunk();
|
||||
uploadedSize += chunkSize;
|
||||
const currentProgress = Math.floor((uploadedSize / file.size) * 100);
|
||||
setProgress(currentProgress);
|
||||
|
||||
chunkNumber++;
|
||||
start = end;
|
||||
|
||||
await uploadNextChunk();
|
||||
} catch (error) {
|
||||
setError(error as Error, "Failed to upload file");
|
||||
setProgress(0);
|
||||
}
|
||||
};
|
||||
|
||||
uploadNextChunk();
|
||||
|
||||
Reference in New Issue
Block a user