From 0456139a167790d3afe8d8f07631df58738dd9b2 Mon Sep 17 00:00:00 2001 From: Wilhelm Date: Thu, 12 Oct 2023 09:46:55 +0200 Subject: [PATCH] chore(merge): fixed merge issues --- src/hooks/useAnalogueModels.tsx | 81 ---------------------------- src/pages/ModelPages/Model/Model.tsx | 4 +- 2 files changed, 2 insertions(+), 83 deletions(-) delete mode 100644 src/hooks/useAnalogueModels.tsx diff --git a/src/hooks/useAnalogueModels.tsx b/src/hooks/useAnalogueModels.tsx deleted file mode 100644 index 3c7f96fe..00000000 --- a/src/hooks/useAnalogueModels.tsx +++ /dev/null @@ -1,81 +0,0 @@ -/* eslint-disable max-lines-per-function */ -import { useQuery } from '@tanstack/react-query'; -import axios from 'axios'; -import type { ParamsOption, RequestBodyOption } from 'openapi-fetch'; -import { useApiClient } from '../context/ApiClientProvider'; -import { paths } from '../models/schema'; -import { useAccessToken } from './useAccessToken'; - -type UseQueryOptions = ParamsOption & - RequestBodyOption & { - // custom options - params?: { path: { id: string } }; - }; - -const ANALOGUEMODELS_KEY = '/api/analogue-models'; -const ANALOGUEMODEL_KEY = '/api/analogue-models/{id}'; -const NC_FILE_KEY = '/api/analogue-models/{id}/input-models'; - -export function useAnalogueModels(id: string) { - const apiClient = useApiClient(); - const token = useAccessToken(); - const headers = new Headers({ Authorization: `Bearer ${token}` }); - - async function fetchModels(): AnalogueModelResponse { - const { data } = await apiClient.GET(ANALOGUEMODELS_KEY, { - headers: headers, - }); - return data; - } - - async function fetchModel(id: string): AnalogueModelResponse { - const params = { path: { id } }; - - const { data } = await apiClient.GET(ANALOGUEMODEL_KEY, { - params, - headers: headers, - }); - - return data; - } - - async function createModel({ - body, - }: UseQueryOptions) { - const { data } = await apiClient.POST(ANALOGUEMODELS_KEY, { - body, - headers: headers, - }); - return data; - } - - async function uploadNCFile(id: string, file: File) { - axios.defaults.baseURL = process.env.REACT_APP_BACKEND_ENV; - const form = new FormData(); - form.append('file', file); - const { data } = await axios.post(NC_FILE_KEY.replace('{id}', id), form, { - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'multipart/form-data', - }, - }); - return data; - } - - const models = useQuery(['models', token], fetchModels, { enabled: !!token }); - // TODO: might want to add queryFn to this: - - const model: AnalogueModel = useQuery({ - queryKey: ['model', token, id], - queryFn: () => fetchModel(id), - - enabled: !!id, - }); - - return { - model, - createModel, - models, - uploadNCFile, - }; -} diff --git a/src/pages/ModelPages/Model/Model.tsx b/src/pages/ModelPages/Model/Model.tsx index b768e632..5a61cc93 100644 --- a/src/pages/ModelPages/Model/Model.tsx +++ b/src/pages/ModelPages/Model/Model.tsx @@ -8,12 +8,12 @@ import { AnalogueModelsService } from '../../../api/generated'; export const Model = () => { const { id } = useParams<{ id: string }>(); - const { data } = useQuery({ + const { data, isLoading } = useQuery({ queryKey: ['analogue-models', id], queryFn: () => AnalogueModelsService.getApiAnalogueModels1(id as string), }); - if (model.isLoading)

Loading.....

; + if (isLoading)

Loading.....

; return ( <>