-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
84 lines (72 loc) · 3 KB
/
App.tsx
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
80
81
82
83
import { useWindowDimensions } from '@figurl/core-utils';
import { SetupStyleSettings } from '@figurl/franklab-views';
import { getFigureData, SetupUrlState } from '@figurl/interface';
import { defaultUnitSelection, SetupSortingCuration, UnitMetricSelectionContext, unitMetricSelectionReducer, UnitSelectionContext, unitSelectionReducer } from '@figurl/spike-sorting-views';
import { SetupAnnotations, SetupTimeseriesSelection } from '@figurl/timeseries-views';
import { MuiThemeProvider } from '@material-ui/core';
import { useEffect, useMemo, useReducer, useState } from 'react';
import './localStyles.css';
import theme from './theme';
import View from './View';
const urlSearchParams = new URLSearchParams(window.location.search)
const queryParams = Object.fromEntries(urlSearchParams.entries())
// Example: https://www.figurl.org/f?v=http://localhost:3000&d=sha1://c7e0ae023c4c75d9ae85078e459d7fc8daa1224d&label=Track%20position%20animation%20example&s={}
function App() {
const [data, setData] = useState<any>()
const [errorMessage, setErrorMessage] = useState<string>()
const {width, height} = useWindowDimensions()
const [unitSelection, unitSelectionDispatch] = useReducer(unitSelectionReducer, defaultUnitSelection)
const [unitMetricSelection, unitMetricSelectionDispatch] = useReducer(unitMetricSelectionReducer, {})
useEffect(() => {
if (queryParams.test === '1') {
// To test the Test1View without using the figurl parent
// for example, with no internet connection,
// use http://localhost:3000?test=1
setData({type: 'Test1'})
}
else {
getFigureData().then((data: any) => {
if (!data) {
setErrorMessage('No data in return from getFigureData()')
return
}
setData(data)
}).catch((err: any) => {
setErrorMessage(`Error getting figure data`)
console.error(`Error getting figure data`, err)
})
}
}, [])
const opts = useMemo(() => ({}), [])
if (errorMessage) {
return <div style={{color: 'red'}}>{errorMessage}</div>
}
if (!data) {
return <div>Waiting for data</div>
}
return (
<MuiThemeProvider theme={theme}>
<SetupTimeseriesSelection>
<UnitSelectionContext.Provider value={{unitSelection, unitSelectionDispatch}}>
<UnitMetricSelectionContext.Provider value={{unitMetricSelection, unitMetricSelectionDispatch}}>
<SetupAnnotations>
<SetupUrlState>
<SetupSortingCuration>
<SetupStyleSettings>
<View
data={data}
opts={opts}
width={width - 10}
height={height - 5}
/>
</SetupStyleSettings>
</SetupSortingCuration>
</SetupUrlState>
</SetupAnnotations>
</UnitMetricSelectionContext.Provider>
</UnitSelectionContext.Provider>
</SetupTimeseriesSelection>
</MuiThemeProvider>
)
}
export default App;