fix api auth

This commit is contained in:
Sara
2023-11-02 16:03:10 +01:00
parent 0d9f66c097
commit e65efb841f
12 changed files with 118 additions and 99 deletions

View File

@@ -5,6 +5,7 @@ import {
} from "../../api/apis/DefaultApi";
import { AudioWaveform } from "../../api";
import { useError } from "../../(errors)/errorContext";
import getApi from "../../lib/getApi";
type AudioWaveFormResponse = {
waveform: AudioWaveform | null;
@@ -12,14 +13,15 @@ type AudioWaveFormResponse = {
error: Error | null;
};
const useWaveform = (api: DefaultApi, id: string): AudioWaveFormResponse => {
const useWaveform = (protectedPath, id: string): AudioWaveFormResponse => {
const [waveform, setWaveform] = useState<AudioWaveform | null>(null);
const [loading, setLoading] = useState<boolean>(false);
const [loading, setLoading] = useState<boolean>(true);
const [error, setErrorState] = useState<Error | null>(null);
const { setError } = useError();
const api = getApi(protectedPath);
const getWaveform = (id: string) => {
if (!id) return;
useEffect(() => {
if (!id || !api) return;
setLoading(true);
const requestParameters: V1TranscriptGetAudioWaveformRequest = {
@@ -36,11 +38,7 @@ const useWaveform = (api: DefaultApi, id: string): AudioWaveFormResponse => {
setError(err);
setErrorState(err);
});
};
useEffect(() => {
getWaveform(id);
}, [id]);
}, [id, api]);
return { waveform, loading, error };
};