From 22b45654f0d6b0a543127108dd30e51f1d776b13 Mon Sep 17 00:00:00 2001 From: mheggelund Date: Mon, 18 Sep 2023 13:44:46 +0200 Subject: [PATCH] feat: Add model page, closes #61 --- src/pages/Compute/Compute.tsx | 7 ++++++ src/pages/Model/Model.styled.tsx | 14 +++++++++++ src/pages/Model/Model.tsx | 41 ++++++++++++++++++++++++++++++++ src/pages/Results/Results.tsx | 7 ++++++ src/router.tsx | 26 +++++++++++++++++++- 5 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 src/pages/Compute/Compute.tsx create mode 100644 src/pages/Model/Model.styled.tsx create mode 100644 src/pages/Model/Model.tsx create mode 100644 src/pages/Results/Results.tsx diff --git a/src/pages/Compute/Compute.tsx b/src/pages/Compute/Compute.tsx new file mode 100644 index 00000000..b51c33b9 --- /dev/null +++ b/src/pages/Compute/Compute.tsx @@ -0,0 +1,7 @@ +export const Compute = () => { + return ( +
+

Compute models here!

+
+ ) +} diff --git a/src/pages/Model/Model.styled.tsx b/src/pages/Model/Model.styled.tsx new file mode 100644 index 00000000..8c6a0f48 --- /dev/null +++ b/src/pages/Model/Model.styled.tsx @@ -0,0 +1,14 @@ +import styled from 'styled-components' + +export const Wrapper = styled.div` + display: flex; + flex: auto; + flex-direction: row; + position: relative; + width: 100%; +` + +export const SidebarWrapper = styled.div` + heigth: 100%; + max-width: 256px; +` diff --git a/src/pages/Model/Model.tsx b/src/pages/Model/Model.tsx new file mode 100644 index 00000000..2ce86c05 --- /dev/null +++ b/src/pages/Model/Model.tsx @@ -0,0 +1,41 @@ +import { useEffect, useState } from 'react' +import { Outlet, useParams } from 'react-router-dom' +import { useAnalogueModels } from '../../hooks/useAnalogueModels' +import { components } from '../../models/schema' +import * as Styled from './Model.styled' + +import { ModelNameFrame } from '../../features/ModelView/ModelNameFrame/ModelNameFrame' +import { ModelNavigationBar } from '../../features/ModelView/ModelNavigationBar/ModelNavigationBar' + +export type ModelType = Partial< + components['schemas']['GetAnalogueModelQueryResponse']['data'] +> + +export const Model = () => { + const [model, setModel] = useState() + const { id } = useParams() + const { fetchModel } = useAnalogueModels() + + useEffect(() => { + async function getModel() { + return await fetchModel({ + params: { path: { id: id ?? '' } }, + }).then((response) => response?.data) + } + if (!model) { + getModel().then((model) => model && setModel(model as ModelType)) + } + }, [id, model, fetchModel]) + + return ( + <> + {model && } + + + + + + + + ) +} diff --git a/src/pages/Results/Results.tsx b/src/pages/Results/Results.tsx new file mode 100644 index 00000000..bcf292e9 --- /dev/null +++ b/src/pages/Results/Results.tsx @@ -0,0 +1,7 @@ +export const Results = () => { + return ( +
+

Resukts for models here!

+
+ ) +} diff --git a/src/router.tsx b/src/router.tsx index 76156f4f..acad5759 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -1,6 +1,10 @@ import { createBrowserRouter, NonIndexRouteObject } from 'react-router-dom' import { App } from './App' +import { ModelView } from './features/ModelView/ModelView' import { Browse } from './pages/Browse/Browse' +import { Compute } from './pages/Compute/Compute' +import { Model } from './pages/Model/Model' +import { Results } from './pages/Results/Results' interface Tab extends Required> { title: string @@ -17,12 +21,32 @@ const tabs: Tab[] = [ { title: 'API', path: 'api', element: }, { title: 'About', path: 'about', element: }, ] +const appRoutes = (tabs as NonIndexRouteObject[]).concat([ + { + path: 'model/:id/', + element: , + children: [ + { + path: 'details', + element: , + }, + { + path: 'compute', + element: , + }, + { + path: 'results', + element: , + }, + ], + }, +]) const router = createBrowserRouter([ { path: '/', element: , - children: tabs, + children: appRoutes, }, { path: '*',