forked from driusan/brainviewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
105 lines (97 loc) · 2.91 KB
/
App.js
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import 'react-native-gesture-handler';
import { GestureHandlerRootView} from 'react-native-gesture-handler';
import {StatusBar} from 'expo-status-bar';
import {StyleSheet, View, Text, ScrollView} from 'react-native';
import React, {useEffect, useState} from 'react';
import {hdf5Loader} from './MincLoader';
import {Viewer} from './Viewer';
import {Login} from './Login';
import * as SecureStore from 'expo-secure-store';
async function getValueFor(key) {
return await SecureStore.getItemAsync(key);
}
export default function App() {
const [token, setToken] = useState(null);
const [returnData, setReturnData] = useState(null);
const [rawData, setRawData] = useState(null);
const [headerData, setHeaderData] = useState(null);
const [shouldScroll, setShouldScroll] = useState(true);
useEffect(() => {
if (token)
return;
getValueFor('loris_token').then((lorisToken) => {
if (lorisToken)
setToken(lorisToken);
});
}, [token])
useEffect(() => {
// Get file from LORIS
if (!token) {
return;
}
// Fetch in react native does not support ArrayBuffer
const req = new XMLHttpRequest();
req.open('GET', 'https://demo-25-0.loris.ca/api/v0.0.3/candidates/587630/V1/images/demo_587630_V1_t2_001_t2-defaced_001.mnc', true);
req.responseType = "arraybuffer";
req.setRequestHeader('Authorization', 'Bearer ' + token);
req.onload = (evt) => {
if (req.status < 200 || req.status >= 300) {
console.log('response status', req.status);
SecureStore.deleteItemAsync('loris_token', null);
setToken(null);
return;
}
var result = hdf5Loader(req.response);
setRawData(result.raw_data);
setHeaderData(JSON.parse(result.header_text));
};
req.send(null);
}, [token]);
if (!token) {
return (
<Login
token={token}
setToken={setToken}
/>
)
}
return (
// ScrollView
<ScrollView scrollEnabled={shouldScroll} style={styles.container}>
<GestureHandlerRootView styles={{flex: 1}}>
<Text></Text>
<Text> </Text>
<Text> </Text>
<Text> </Text>
<View >
<Text style={{
textAlign: "center", fontSize: 25
}}>
Welcome to our Mobile Native BrainViewer!
</Text>
</View>
<View >
<Text style={{
textAlign: "center", fontSize: 15
}}>
By Dave MacFarlane, Camille Beaudoin, and Jefferson Casimir
</Text>
</View>
<Text> </Text>
<Viewer rawData={rawData} headers={headerData}
onGestureStart={ () => setShouldScroll(false) }
onGestureEnd={ () => setShouldScroll(true) }
/>
<StatusBar style="auto" />
<Text></Text>
<Text></Text>
</GestureHandlerRootView>
</ScrollView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
},
});