-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathApp.jsx
More file actions
79 lines (71 loc) · 2.37 KB
/
App.jsx
File metadata and controls
79 lines (71 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// src/App.jsx
import React, { useState, useEffect } from 'react'
import CircularProgress from '@mui/material/CircularProgress'
import axios from 'axios'
import Home from './home'
import Factsheet from './components/scenarioBundle'
import ComparisonBoardMain from './components/comparisonBoardMain'
import HistoryTable from './components/historyTable'
import Diff from './components/oekg_modifications'
import './styles/App.css'
import conf from './conf.json'
function App() {
console.log('🏠 App rendered');
const [factsheet, setFactsheet] = useState(null)
const [loading, setLoading] = useState(true)
// split all path segments, e.g. '/scenario-bundles/id/NEW' → ['scenario-bundles','id','NEW']
const [resource, route, idOrNew] =
window.location.pathname.split('/').slice(1)
useEffect(() => {
async function fetchData() {
// only fetch when route==='id' and we have an id/new
if (resource === 'scenario-bundles' && route === 'id' && idOrNew) {
try {
const { data } = await axios.get(
`${conf.toep}scenario-bundles/get/`,
{ params: { id: idOrNew } }
)
setFactsheet(data)
} catch (err) {
console.error('Fetch error:', err)
}
}
setLoading(false)
}
fetchData()
}, [resource, route, idOrNew])
// top-level routes that don’t need data
if (resource === 'scenario-bundles' && route === 'main') {
return <Home />
}
if (resource === 'scenario-bundles' && route === 'oekg_history') {
return <HistoryTable />
}
if (resource === 'scenario-bundles' && route === 'oekg_modifications') {
return <Diff />
}
if (!loading) {
if (resource === 'scenario-bundles' && route === 'compare') {
const uidString = window.location.pathname.split('/')[3] || '';
const uids = uidString.split('&'); // ✅ split into array
return <ComparisonBoardMain params={uids} />
}
// now matches both '/scenario-bundles/id/new' and '/scenario-bundles/id/<uuid>'
if (resource === 'scenario-bundles' && route === 'id' && idOrNew) {
return <Factsheet id={idOrNew} fsData={factsheet || {}} />
}
return null
}
// still loading
return (
<div style={{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
height: '100vh'
}}>
<CircularProgress />
</div>
)
}
export default App