-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeed.js
More file actions
132 lines (129 loc) · 3.22 KB
/
Copy pathFeed.js
File metadata and controls
132 lines (129 loc) · 3.22 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
128
129
130
131
132
'use strict';
import React, {Component} from 'react';
import AuthService from './AuthService';
import {
Text,
View,
ListView,
ActivityIndicator,
Image,
TouchableHighlight
} from 'react-native';
import moment from 'moment';
import PushPayload from './PushPayload';
export default class Feed extends Component < {} > {
constructor(props) {
super(props);
const ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 != r2
});
this.state = {
dataSource: ds,
showProgress: true
}
this.fetchFeed.bind(this);
this.pressRow.bind(this);
}
componentDidMount() {
this.fetchFeed();
}
fetchFeed(){
AuthService.getAuthInfo((err, authInfo) => {
var url = 'https://api.github.com/users/'
+ authInfo.user.login
+ '/received_events';
fetch(url, {
headers: authInfo.header
})
.then((response) => response.json())
.then((responseData) => {
var feedItems = responseData.filter((ev) => ev.type == 'PushEvent');
this.setState({
dataSource: this.state.dataSource
.cloneWithRows(feedItems),
showProgress: false
});
})
});
}
pressRow(rowData) {
this.props.navigator.push({
title: 'Push Event',
component: PushPayload,
passProps: {
pushEvent: rowData
}
});
}
renderRow(rowData) {
return (
<TouchableHighlight
onPress={() => this.pressRow(rowData)}
underlayColor='#ddd'
>
<View style={{
flex: 1,
flexDirection: 'row',
padding: 20,
alignItems: 'center',
borderColor: '#D7D7D7',
borderBottomWidth: 1
}}>
<Image
source={{uri: rowData.actor.avatar_url}}
style={{
height: 36,
width: 36,
borderRadius: 18,
}}
/>
<View style={{
paddingLeft: 20
}}>
<Text style={{backgroundColor: '#fff'}}>
{moment(rowData.created_at).fromNow()}
</Text>
<Text style={{backgroundColor: '#fff'}}>
<Text style={{
fontWeight: "600"
}}>{rowData.actor.login} </Text> pushed to
</Text>
<Text style={{backgroundColor: '#fff'}}>
{rowData.payload.ref.replace('refs/heads/', '')}
</Text>
<Text style={{backgroundColor: '#fff'}}>
at <Text style={{
fontWeight: "600"
}}>{rowData.repo.name} </Text>
</Text>
</View>
</View>
</TouchableHighlight>
);
}
render() {
if(this.state.showProgress){
return (
<View style={{
flex: 1,
justifyContent: 'center'
}}>
<ActivityIndicator
size="large"
animating={true} />
</View>
);
}
return (
<View style={{
flex: 1,
justifyContent: 'flex-start',
paddingTop: 30
}}>
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderRow.bind(this)} />
</View>
);
}
}