Skip to content

Commit

Permalink
fix: violation of hook rules
Browse files Browse the repository at this point in the history
  • Loading branch information
olavis committed Sep 18, 2023
1 parent 8bf2047 commit f58af1b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
29 changes: 19 additions & 10 deletions src/hooks/useAnalogueModels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,32 @@ export function useAnalogueModels() {
return data
}

const NC = ({
async function uploadNCFile({
params,
body,
}: UseQueryOptions<paths[typeof NC_FILE_KEY]['post']>) =>
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<paths[typeof NC_FILE_KEY]['post']>) {
const { data } = await apiClient.POST(NC_FILE_KEY, {
params,
body,
headers: new Headers({ Authorization: `Bearer ${token}` }),
})
return data
}

// async function NC({
// params,
// body,
// }: UseQueryOptions<paths[typeof NC_FILE_KEY]['post']>) {
// 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 }
}
6 changes: 3 additions & 3 deletions src/pages/Browse/Browse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ enum UploadProcess {
}

export const Browse = () => {
const { createModel, NC } = useAnalogueModels()
const { createModel, uploadNCFile } = useAnalogueModels()
const [isAddModelDialog, setAddModelDialog] = useState<boolean>(false)
const [uploadStatus, setUploadStatus] = useState<string>()
const testModel = {
Expand All @@ -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' },
})
Expand Down

0 comments on commit f58af1b

Please sign in to comment.