Skip to content

Commit

Permalink
refactor: turn into typescdript
Browse files Browse the repository at this point in the history
  • Loading branch information
pbullhove committed Apr 2, 2024
1 parent 12bd291 commit 0c1ff7b
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 189 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
web/node_modules
/.idea/
/api/.venv/
**/build
**/__pycache__/**
log.txt
.env
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ services:
web:
build:
context: ./web
target: prod
# target: development
# target: prod
target: development
restart: unless-stopped
stdin_open: true
volumes:
Expand Down
186 changes: 0 additions & 186 deletions web/src/Components/Bridging/BridgeContainer.jsx

This file was deleted.

96 changes: 96 additions & 0 deletions web/src/Components/Bridging/BridgeContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { useContext, useEffect, useState } from 'react'
import { FractionsAPI } from '../../Api'
import { BridgingOption, CeramicDiscsValues } from '../../Enums'
import { AuthContext } from 'react-oauth2-code-pkce'
import BridgeGraph from './BridgeGraph'
import { ErrorToast } from '../Common/Toast'
import InputContainer from './InputContainer'
import { findGraphData } from '../../Utils'

export default ({ bridges, mode, setMode, bridgeValue, setValue }) => {
const [sizeFractions, setSizeFractions] = useState([])
const [unit, setUnit] = useState('mD')
const [bridgeValueHelperText, setBridgeValueHelperText] = useState(undefined)
const [bridgeValueVariant, setBridgeValueVariant] = useState(undefined)
const [optimalBridgeGraphData, setOptimalBridgeGraphData] = useState([])
const { token } = useContext(AuthContext)

// Load size fractions once on first render
useEffect(() => {
FractionsAPI.getFractionsApi(token)
.then(response => {
setSizeFractions(response.data.size_fractions)
})
.catch(error => {
ErrorToast(`${error.response.data}`, error.response.status)
console.error('fetch error' + error)
})
}, [])

useEffect(() => {
if (bridges['Bridge'].length && sizeFractions.length) {
const x = findGraphData(sizeFractions, { Bridge: bridges['Bridge'] })
setOptimalBridgeGraphData(x)
}
}, [bridges, sizeFractions])

function onBridgeOptionChange(event) {
switch (event.target.value) {
case BridgingOption.PERMEABILITY:
setMode(BridgingOption.PERMEABILITY)
setUnit('mD')
break
case BridgingOption.AVERAGE_PORESIZE:
setMode(BridgingOption.AVERAGE_PORESIZE)
setUnit('microns')
break

case BridgingOption.MAXIMUM_PORESIZE:
setMode(BridgingOption.MAXIMUM_PORESIZE)
setUnit('microns')
break
case BridgingOption.CERAMIC_DISCS:
setMode(BridgingOption.CERAMIC_DISCS)
setUnit('microns')
setValue(CeramicDiscsValues[0])
break
default:
return
}
}

function onBridgeValueChange(value) {
const newBridgeValue = parseInt(value)
// TODO: Setting invalid values on parent is not good
setValue(newBridgeValue)

if (Math.sign(newBridgeValue) !== 1) {
setBridgeValueHelperText('Value must be an integer bigger than 0')
setBridgeValueVariant('error')
return
}

setBridgeValueVariant(undefined)
setBridgeValueHelperText(undefined)
}

return (
//<div style={{ display: 'flex' }}>
<div>
<InputContainer
mode={mode}
onBridgeOptionChange={onBridgeOptionChange}
onBridgeValueChange={onBridgeValueChange}
optimalBridgeGraphData={optimalBridgeGraphData}
unit={unit}
bridgeValue={bridgeValue}
bridgeValueVariant={bridgeValueVariant}
bridgeValueHelperText={bridgeValueHelperText}
/>
<div style={{ display: 'flex', alignItems: 'center' }}>
<BridgeGraph bridges={bridges} sizeFractions={sizeFractions} />
<BridgeGraph bridges={bridges} sizeFractions={sizeFractions} />
</div>
</div>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function BridgeGraph({ bridges, sizeFractions }) {
}, [bridges, sizeFractions])

return (
<div>
<div style={{backgroundColor: 'white', borderRadius: '0.5rem'}}>
<AreaChart data={graphData} margin={{ top: 5, right: 30, left: 20, bottom: 5 }} width={980} height={420}>
{/* Defines a gradient applied to the areaPlot to highlight selected particle size range*/}
<defs>
Expand Down
Loading

0 comments on commit 0c1ff7b

Please sign in to comment.