Skip to content

Commit

Permalink
chore: small code clean
Browse files Browse the repository at this point in the history
  • Loading branch information
mheggelund committed Oct 5, 2023
1 parent 577ebd8 commit 78fc600
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<keyof ModelParam>() as ModelParam
const { model } = useAnalogueModels(id)

if (model.isLoading) <p>Loading.....</p>

Expand Down
7 changes: 4 additions & 3 deletions src/features/ModelView/ModelSourceView/ModelSourceView.tsx
Original file line number Diff line number Diff line change
@@ -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<keyof ModelParam>() as ModelParam
const { model } = useAnalogueModels(id)

if (model.isLoading) <p>Loading.....</p>

Expand All @@ -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) => (
<Table.Row key={file.uploadId} className="table-row">
<Table.Cell className="table-first-col">
{file.originalFileName}
Expand Down
25 changes: 10 additions & 15 deletions src/hooks/useAnalogueModels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -50,31 +49,27 @@ 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
}

const models = useQuery(['models', token], fetchModels, { enabled: !!token })
// 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 {
Expand Down
5 changes: 3 additions & 2 deletions src/pages/ModelPages/Model/Model.tsx
Original file line number Diff line number Diff line change
@@ -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<keyof ModelParam>() as ModelParam
const { model } = useAnalogueModels(id)

if (model.isLoading) <p>Loading.....</p>

Expand Down

0 comments on commit 78fc600

Please sign in to comment.