Newer
Older
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
// import { StatusBar } from 'expo-status-bar';
// import React from 'react';
// import { StyleSheet, Text, View } from 'react-native';
// import { NavigationContainer } from '@react-navigation/native';
// import { createStackNavigator } from '@react-navigation/stack';
// function HomeScreen() {
// return (
// <View style={viewStyleVertical}>
// <Text>Home Screen</Text>
// </View>
// );
// }
// const Stack = createStackNavigator();
// export default function App() {
// return (
// <View style={styles.container}>
// <Text>Open up App.js to start working on your app!!!</Text>
// <StatusBar style="auto" />
// <NavigationContainer>
// <Stack.Navigator>
// <Stack.Screen name="Home" component={HomeScreen} />
// </Stack.Navigator>
// </NavigationContainer>
// </View>
// );
// }
// const styles = StyleSheet.create({
// container: {
// flex: 1,
// backgroundColor: '#fff',
// alignItems: 'center',
// justifyContent: 'center',
// },
// });
import * as React from 'react';
import { Pressable, View, Text, Image, StyleSheet, ImageBackground } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
const Stack = createStackNavigator();
const styles = StyleSheet.create({
viewStyleVertical : { alignItems: 'center', justifyContent: 'center', margin: '10%' },
viewStyleHorizon : { flex: 1, flexDirection: 'row', justifyContent: 'space-between'},
pressableStyle : {flex: 1, flexDirection: 'row', justifyContent: 'space-between', backgroundColor:'lavender', paddingHorizontal:20,
paddingVertical:10, borderColor:'thistle', borderWidth:2, borderRadius:5, marginHorizontal: 10, marginTop: 10},
image: { flex: 1, resizeMode: "cover", justifyContent: "center"},
container : {flex: 1},
textBox : {flex: 1, marginTop: 20, backgroundColor:'white', borderColor:'black', borderWidth:2, borderRadius:5,
marginHorizontal: 10, paddingVertical:10, paddingHorizontal: 50, alignItems: 'flex-start'}
});
/** Home page **/
function HomeScreen({ navigation }) {
return (
<View style={styles.container}>
<ImageBackground source={require('C:/Coding/cs242-assignment3/GitView/assets/ice.jpg')} style={styles.image}>
<View style={styles.viewStyleVertical}>
<Pressable style={styles.pressableStyle} onPress={() => navigation.navigate('LoadingProfile')}>
<Text> Start </Text>
</Pressable>
</View>
</ImageBackground>
</View>
);
}
/** Profile page **/
function ProfileScreen({ route, navigation }) {
const {name, login, avatarUrl, bio, createdAt, email, websiteUrl, repositories} = route.params;
const nameContent = 'Name: \n' + name;
const userNameContent = 'UserName\n: ' + login
const bioContent = 'Bio: \n' + bio
const createDate = 'Create at: \n' + createdAt
const emailContent = 'Email: \n' + email
const websiteLink = 'Website: \n' + websiteUrl
const repoCount = 'Repository count: ' + repositories['nodes'].length
console.log(avatarUrl)
var iconUrl
if (avatarUrl != null) {
iconUrl = { uri: avatarUrl }
} else {
iconUrl = require('C:/Coding/cs242-assignment3/GitView/assets/default.png')
}
return (
<View style={styles.container}>
<ImageBackground source={require('C:/Coding/cs242-assignment3/GitView/assets/ice.jpg')} style={styles.image}>
<View style={styles.viewStyleVertical}>
<View style={styles.viewStyleVertical}>
<Image style={{width: 100, height: 100}} source={iconUrl} />
</View>
<View style={styles.viewStyleHorizon}>
<Pressable style={styles.pressableStyle}>
<Text> Followers </Text>
</Pressable>
<Pressable style={styles.pressableStyle}>
<Text> Followings </Text>
</Pressable>
</View>
<View style={styles.viewStyleVertical} >
<Text style={styles.textBox}> {nameContent} </Text>
<Text style={styles.textBox}> {userNameContent} </Text>
<Text style={styles.textBox}> {bioContent} </Text>
<Text style={styles.textBox}> {websiteLink} </Text>
<Text style={styles.textBox}> {emailContent} </Text>
<Text style={styles.textBox}> {createDate} </Text>
</View>
<View style={styles.viewStyleVertical} >
<Pressable style={styles.pressableStyle} onPress={() => navigation.navigate('LoadingRepo')}>
<Text> {repoCount} </Text>
</Pressable>
</View>
</View>
</ImageBackground>
</View>
);
}
/** Repo page **/
function RepoScreen({ route, navigation }) {
const {nodes} = route.params
let cards = [];
for (let i = 0; i < nodes.length; i++) {
var repoName = 'Repo name: \n' + nodes[i]['name'] + '\n'
var repoDescription = 'Repo description: \n' + nodes[i]['description'] + '\n'
var repoOwner = 'Repo owner: \n' + nodes[i]['owner']['login'] + '\n'
var nativeID = 'repo#' + i
cards.push(
<View style={styles.textBox} nativeID={nativeID}>
<Text> {repoName} </Text>
<Text> {repoDescription} </Text>
<Text> {repoOwner} </Text>
</View>
)
}
return (
<View style={styles.container}>
<ImageBackground source={require('C:/Coding/cs242-assignment3/GitView/assets/ice.jpg')} style={styles.image}>
<View style={styles.viewStyleVertical}>
{cards}
<Pressable style={styles.pressableStyle} onPress={() => navigation.navigate('Profile')}>
<Text> Go to Profile </Text>
</Pressable>
</View>
</ImageBackground>
</View>
);
}
/** Unfound page **/
function UnfoundScreen({ route, navigation }) {
const {errorMsg} = route.params
console.error(errorMsg)
return (
<View style={styles.container}>
<ImageBackground source={require('C:/Coding/cs242-assignment3/GitView/assets/ice.jpg')} style={styles.image}>
<View style={styles.viewStyleVertical}>
<Text style={{ fontSize: 30 }}> Error! Check log to see details </Text>
<Image style={{width: 200, height: 200}} source={require('C:/Coding/cs242-assignment3/GitView/assets/warn.png')} />
<Pressable style={styles.pressableStyle} onPress={() => navigation.navigate('Home')}>
<Text> Go back to Home Page </Text>
</Pressable>
</View>
</ImageBackground>
</View>
);
}
/** Loading Profile page **/
function LoadProfileScreen({navigation}) {
const dataJson = require('C:/Coding/cs242-assignment3/env.json');
fetch(dataJson['endPoint'], {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Authorization": dataJson['token']
},
body: JSON.stringify({
query: `
query {
viewer {
name
login
avatarUrl
bio
createdAt
email
websiteUrl
repositories(last:100, privacy:PUBLIC){
nodes{
name
}
}
}
}
`
})
})
.then(res => res.json())
.then((data)=> {
navigation.navigate('Profile', data['data']['viewer'])
})
.catch(error => {
console.error('Error:', error)
navigation.navigate('Unfound', {errorMsg: error})
})
return (
<View style={styles.container}>
<ImageBackground source={require('C:/Coding/cs242-assignment3/GitView/assets/ice.jpg')} style={styles.image}>
<View style={styles.viewStyleVertical}>
<Text style={{ fontSize: 30 }}>Loading......</Text>
<Image style={{width: 200, height: 200}} source={require('C:/Coding/cs242-assignment3/GitView/assets/loading.png')} />
</View>
</ImageBackground>
</View>
);
}
/** Loading Repo page **/
function LoadRepoScreen({navigation}) {
// setTimeout(function(){
// navigation.navigate('Unfound');
// }, 1000)
const dataJson = require('C:/Coding/cs242-assignment3/env.json');
fetch(dataJson['endPoint'], {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Authorization": dataJson['token']
},
body: JSON.stringify({
query: `
query {
viewer{
repositories(last:100, privacy:PUBLIC){
nodes{
name
owner{
login
}
description
}
}
}
}
`
})
})
.then(res => res.json())
// .then((data) => console.log(data['data']['viewer']['repositories']['nodes']))
// .then((data) => console.log(data))
.then((data)=> {
navigation.navigate('Repo', data['data']['viewer']['repositories'])
})
.catch(error => {
console.error('Error:', error)
navigation.navigate('Unfound', {errorMsg: error})
})
return (
<View style={styles.container}>
<ImageBackground source={require('C:/Coding/cs242-assignment3/GitView/assets/ice.jpg')} style={styles.image}>
<View style={styles.viewStyleVertical}>
<Text style={{ fontSize: 30 }}>Loading......</Text>
<Image style={{width: 200, height: 200}} source={require('C:/Coding/cs242-assignment3/GitView/assets/loading.png')} />
</View>
</ImageBackground>
</View>
);
}
/** Page loader **/
function App() {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="Home">
<Stack.Screen name="Home" component={HomeScreen} options={{ title: 'Github User Info' }}/>
<Stack.Screen name="Profile" component={ProfileScreen} />
<Stack.Screen name="Repo" component={RepoScreen} options={{ title: 'Repositories' }}/>
<Stack.Screen name="LoadingProfile" component={LoadProfileScreen} />
<Stack.Screen name="LoadingRepo" component={LoadRepoScreen} />
<Stack.Screen name="Unfound" component={UnfoundScreen} options={{ title: 'Error' }}/>
</Stack.Navigator>
</NavigationContainer>
);
}
export default App;