From e4860f2f6537d05762b681837bca52a650dbebae Mon Sep 17 00:00:00 2001 From: Olava Faksdal <38139899+olavis@users.noreply.github.com> Date: Thu, 7 Sep 2023 15:03:01 +0200 Subject: [PATCH] fix: violation of hook rules --- src/hooks/useAnalogueModels.tsx | 29 +++++++++++++++++++---------- src/pages/Browse/Browse.tsx | 6 +++--- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/hooks/useAnalogueModels.tsx b/src/hooks/useAnalogueModels.tsx index 55f6c01b..75e3e82d 100644 --- a/src/hooks/useAnalogueModels.tsx +++ b/src/hooks/useAnalogueModels.tsx @@ -40,23 +40,32 @@ export function useAnalogueModels() { return data } - const NC = ({ + async function uploadNCFile({ params, body, - }: UseQueryOptions) => - useQuery([NC_FILE_KEY, token, params.path.id], async () => { - const { data } = await apiClient.POST(NC_FILE_KEY, { - params, - body, - headers: new Headers({ Authorization: `Bearer ${token}` }), - }) - return data + }: UseQueryOptions) { + const { data } = await apiClient.POST(NC_FILE_KEY, { + params, + body, + headers: new Headers({ Authorization: `Bearer ${token}` }), }) + return data + } + + // async function NC({ + // params, + // body, + // }: UseQueryOptions) { + // return useQuery( + // [NC_FILE_KEY, token, params.path.id], + // async () => await uploadNCFile(params, body) + // ) + // } const models = useQuery( [ANALOGUEMODELS_KEY, token], async () => await fetchModels() ) - return { fetchModels, createModel, models, NC } + return { fetchModels, createModel, models, uploadNCFile } } diff --git a/src/pages/Browse/Browse.tsx b/src/pages/Browse/Browse.tsx index 1ee03e4c..ac5ce0e5 100644 --- a/src/pages/Browse/Browse.tsx +++ b/src/pages/Browse/Browse.tsx @@ -10,7 +10,7 @@ enum UploadProcess { } export const Browse = () => { - const { createModel, NC } = useAnalogueModels() + const { createModel, uploadNCFile } = useAnalogueModels() const [isAddModelDialog, setAddModelDialog] = useState(false) const [uploadStatus, setUploadStatus] = useState() const testModel = { @@ -27,12 +27,12 @@ export const Browse = () => { setAddModelDialog(!isAddModelDialog) } - async function uploadModel(file: File | string) { + async function uploadModel(file: File) { setUploadStatus(UploadProcess.STARTED) await createModel({ body: testModel }) .then((model) => model?.data.analogueModelId) .then((id) => { - NC({ + uploadNCFile({ params: { path: { id: id ?? '' } }, body: { File: file, FileType: 'NetCDF' }, })