diff --git a/src/features/ModelView/ModelMetadataView/ModelMetadataView.tsx b/src/features/ModelView/ModelMetadataView/ModelMetadataView.tsx index b01da32b..ba0a546f 100644 --- a/src/features/ModelView/ModelMetadataView/ModelMetadataView.tsx +++ b/src/features/ModelView/ModelMetadataView/ModelMetadataView.tsx @@ -2,9 +2,12 @@ import { Button, Table, Typography } from '@equinor/eds-core-react' import { useParams } from 'react-router-dom' import { useAnalogueModels } from '../../../hooks/useAnalogueModels' +export type ModelParam = { + id: string +} export const ModelMetadataView = () => { - const { id } = useParams<{ id: string }>() - const { model } = useAnalogueModels(id!) + const { id } = useParams() as ModelParam + const { model } = useAnalogueModels(id) if (model.isLoading)

Loading.....

diff --git a/src/features/ModelView/ModelSourceView/ModelSourceView.tsx b/src/features/ModelView/ModelSourceView/ModelSourceView.tsx index 4769117a..bc8cb5a3 100644 --- a/src/features/ModelView/ModelSourceView/ModelSourceView.tsx +++ b/src/features/ModelView/ModelSourceView/ModelSourceView.tsx @@ -1,9 +1,10 @@ import { Table, Typography } from '@equinor/eds-core-react' import { useParams } from 'react-router-dom' import { useAnalogueModels } from '../../../hooks/useAnalogueModels' +import { ModelParam } from '../ModelMetadataView/ModelMetadataView' export const ModelSourceView = () => { - const { id } = useParams<{ id: string }>() - const { model } = useAnalogueModels(id!) + const { id } = useParams() as ModelParam + const { model } = useAnalogueModels(id) if (model.isLoading)

Loading.....

@@ -25,7 +26,7 @@ export const ModelSourceView = () => { model.isFetched && (model.data.data.fileUploads?.length === undefined || model.data.data.fileUploads?.length > 0) ? ( - model.data.data.fileUploads?.map((file: any) => ( + model.data.data.fileUploads?.map((file: AnalogueModel) => ( {file.originalFileName} diff --git a/src/hooks/useAnalogueModels.tsx b/src/hooks/useAnalogueModels.tsx index 0c9b9506..9b03291b 100644 --- a/src/hooks/useAnalogueModels.tsx +++ b/src/hooks/useAnalogueModels.tsx @@ -20,7 +20,6 @@ export function useAnalogueModels(id: string) { const apiClient = useApiClient() const token = useAccessToken() const headers = new Headers({ Authorization: `Bearer ${token}` }) - const modelId = id async function fetchModels(): AnalogueModelResponse { const { data } = await apiClient.GET(ANALOGUEMODELS_KEY, { @@ -50,20 +49,16 @@ export function useAnalogueModels(id: string) { return data } - async function uploadNCFile(modelId: string, file: File) { + 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}', modelId), - form, - { - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'multipart/form-data', - }, - } - ) + const { data } = await axios.post(NC_FILE_KEY.replace('{id}', id), form, { + headers: { + Authorization: `Bearer ${token}`, + 'Content-Type': 'multipart/form-data', + }, + }) return data } @@ -71,10 +66,10 @@ export function useAnalogueModels(id: string) { // TODO: might want to add queryFn to this: const model: AnalogueModel = useQuery({ - queryKey: ['model', token, modelId], - queryFn: () => fetchModel(modelId), + queryKey: ['model', token, id], + queryFn: () => fetchModel(id), - enabled: !!modelId, + enabled: !!id, }) return { diff --git a/src/pages/ModelPages/Model/Model.tsx b/src/pages/ModelPages/Model/Model.tsx index bede9d02..dd8aaff2 100644 --- a/src/pages/ModelPages/Model/Model.tsx +++ b/src/pages/ModelPages/Model/Model.tsx @@ -1,12 +1,13 @@ import { Outlet, useParams } from 'react-router-dom' +import { ModelParam } from '../../../features/ModelView/ModelMetadataView/ModelMetadataView' import { ModelNameFrame } from '../../../features/ModelView/ModelNameFrame/ModelNameFrame' import { ModelNavigationBar } from '../../../features/ModelView/ModelNavigationBar/ModelNavigationBar' import { useAnalogueModels } from '../../../hooks/useAnalogueModels' import * as Styled from './Model.styled' export const Model = () => { - const { id } = useParams<{ id: string }>() - const { model } = useAnalogueModels(id!) + const { id } = useParams() as ModelParam + const { model } = useAnalogueModels(id) if (model.isLoading)

Loading.....