-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
127 lines (117 loc) · 3.78 KB
/
App.tsx
File metadata and controls
127 lines (117 loc) · 3.78 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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import React, { useEffect, useState } from 'react';
import {
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
Text,
useColorScheme,
View,
ActivityIndicator,
FlatList,
ListRenderItem,
LogBox,
TextInput,
Button,
} from 'react-native';
import { HttpClient, Hub } from './api';
const Section: React.FC<{
title?: string;
}> = ({ children, title }) => {
return (
<View style={styles.sectionContainer}>
{title !== null ? <Text style={[styles.sectionTitle]}>
{title}
</Text> : null}
<Text>
{children}
</Text>
</View>
);
};
const App = () => {
LogBox.ignoreLogs(['VirtualizedLists should never be nested']);
const user_id = "a1152b7cf5004b9ab73f69144f8305b5";
const client = new HttpClient("http://localhost:8080/api", user_id);
const [joinFailed, setJoinFailed] = useState<boolean | null>(null);
const [joinLoading, setJoinLoading] = useState<boolean>(false);
const [joinId, setJoinId] = useState<string>("");
const [createLoading, setCreateLoading] = useState<boolean>(false);
const [createFailed, setCreateFailed] = useState<boolean | null>(null);
const [getFailed, setGetFailed] = useState<boolean | null>(null);
const [getLoading, setGetLoading] = useState<boolean>(false);
const [getId, setGetId] = useState<string>("");
const [hub, setHub] = useState<Hub | null>(null);
const renderItem: ListRenderItem<{ id: string; data: string; }> = ({ item }) => (
<Text>{item.id}: {item.data}</Text>
);
return (
<SafeAreaView>
<Section title="User Info">
Your WICRS user ID is <Text style={styles.highlight}>{user_id}</Text>.
</Section>
<Section title="Join hub">
<View style={styles.part}>
<TextInput
style={{ ...styles.input, width: "100%" }}
placeholder="Enter UUID here..."
onChangeText={id => setJoinId(id)}
value={joinId}
/>
<Button
onPress={() => { setJoinLoading(true); client.joinHub(joinId).then(() => setJoinFailed(false)).catch(() => setJoinFailed(true)).finally(() => setJoinLoading(false)) }}
title="Join"
accessibilityLabel="Joins the hub with the given ID, giving access to it."
/>
{joinFailed !== null ? (joinFailed ? <Text>Failed to join hub</Text> : <Text>Success</Text>) : (joinLoading ? <ActivityIndicator /> : null)}
</View>
</Section>
<Section title="Hub Info">
<View style={styles.part}>
<TextInput
style={{ ...styles.input, width: "100%" }}
placeholder="Enter UUID here..."
onChangeText={id => setGetId(id)}
value={getId}
/>
<Button
onPress={() => { setGetLoading(true); client.getHub(joinId).then((data) => { setHub(data); setGetFailed(false) }).catch(() => setGetFailed(true)).finally(() => setGetLoading(false)) }}
title="Get"
accessibilityLabel="Gets the hub with the given ID and displays it below."
/>
</View>
<View style={styles.part}>
{getFailed !== null ? (getFailed ? <Text>Failed to load hub</Text> : (getLoading ? (<ActivityIndicator />) : (
<Text>Name: {hub?.name}{"\n"}Description: {hub?.description}{"\n"}Channels: {JSON.stringify(hub?.channels)}</Text>
))) : null}
</View>
</Section>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
sectionContainer: {
marginTop: 32,
width: "100%",
paddingHorizontal: 12,
},
part: {
marginTop: 2,
width: "100%",
paddingHorizontal: 2,
},
sectionTitle: {
fontSize: 24,
fontWeight: '600',
},
input: {
height: 40,
margin: 12,
borderWidth: 1,
padding: 10,
},
highlight: {
fontWeight: '700',
},
});
export default App;