-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.js
More file actions
176 lines (157 loc) · 5 KB
/
Copy pathUser.js
File metadata and controls
176 lines (157 loc) · 5 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
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
'use strict';
import React, {
Text,
View,
StyleSheet,
ListView,
Image,
TouchableOpacity,
RefreshControl,
Component,
ScrollView,
InteractionManager,
ActivityIndicatorIOS,
} from 'react-native';
let styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: 20,
backgroundColor:'#333333',
},
face: {
width:60,
height:60,
borderRadius:30,
backgroundColor:'white',
},
header:{
padding:10,
flex:1,
backgroundColor:'#f6f6f6',
color:'#80bd00',
}
});
import Fmt from './Fmt';
import Topic from './Topic';
export default class User extends Component {
constructor(props) {
super(props);
this.state = {
avatar_url: props.avatar_url,
create_at:'',
score:0,
recent_topics:[],
recent_replies:[],
renderPlaceholderOnly: true
};
}
componentWillMount() {
this.load();
}
componentDidMount() {
InteractionManager.runAfterInteractions(() => {
this.setState({renderPlaceholderOnly: false});
});
}
load() {
let url = `https://cnodejs.org/api/v1/user/${this.props.loginname}`;
fetch(url)
.then(res => res.json())
.then(res => {
this.setState({
avatar_url: res.data.avatar_url,
create_at: res.data.create_at,
score: res.data.score,
recent_topics: res.data.recent_topics,
recent_replies: res.data.recent_replies,
});
})
.catch(error => {
console.log(error);
})
.done();
}
_openTopic(topic) {
this.props.navigator.push({
component: Topic,
passProps: { topic: {content:'', ...topic} },
whiteStatus: true,
});
}
renderRow(topic) {
return (
<TouchableOpacity key={topic.id} onPress={this._openTopic.bind(this, topic)}>
<View overflow='hidden' style={{flexDirection:'row', padding:8, flex:1, borderBottomWidth:1, borderBottomColor:'#f0f0f0', backgroundColor:'white',}}>
<View style={{marginRight:10, marginLeft:4}}>
<Image style={{width:36, height:36, borderRadius:18, marginBottom:8, backgroundColor:'#f0f0f0'}} source={{uri:Fmt.fixFaceUrl(topic.author.avatar_url)}}/>
</View>
<View style={{flex:1}}>
<View style={{flexDirection:'row', paddingTop:0, paddingBottom:5}}>
<Text numberOfLines={2} style={{fontSize:16, flex:1, }}>{topic.title}</Text>
</View>
<View style={{flexDirection:'row'}}>
<Text style={{color:'#999', fontSize:12, padding:0}}>{topic.author.loginname}</Text>
<View style={{flex:1}}/>
<Text style={{color:'#999', fontSize:12, padding:0}}>{Fmt.dateDiff(topic.last_reply_at)}</Text>
</View>
</View>
</View>
</TouchableOpacity>
);
}
renderReplies() {
let x = [];
this.state.recent_replies.map((i) => {x.push(this.renderRow(i))})
return x;
}
renderTopics() {
let x = [];
this.state.recent_topics.map((i) => {x.push(this.renderRow(i))})
return x;
}
_renderPlaceholderView() {
return (
<View style={{flex:1, backgroundColor:'white', flexDirection:'column'}}>
<View style={{backgroundColor:'#333333', height:20,}}/>
<View style={{flex:1, justifyContent:'center', alignItems:'center', }}>
<ActivityIndicatorIOS color="grey" size="large" />
</View>
</View>
);
}
render() {
if (this.state.renderPlaceholderOnly) {
return this._renderPlaceholderView();
}
return (
<View style={styles.container}>
<ScrollView>
<View style={{alignItems:'center', justifyContent:'center', backgroundColor:'#333333', paddingTop:8}}>
<Image style={styles.face} source={{uri:this.state.avatar_url}}></Image>
<Text style={{color:'white'}}>{this.props.loginname}</Text>
</View>
<View style={{flexDirection:'row', backgroundColor:'#333333', paddingTop:10}}>
<Text style={{color:'white', margin:10}}>注册时间: {this.state.create_at.substring(0,10)}</Text>
<View style={{flex:1}}/>
<Text style={{color:'white', margin:10}}>积分: {this.state.score}</Text>
</View>
<View style={{backgroundColor:'white',}}>
<Text style={styles.header}>最近回复</Text>
{this.renderReplies()}
</View>
<View style={{backgroundColor:'white',}}>
<Text style={styles.header}>最近发布</Text>
{this.renderTopics()}
</View>
<View style={{height:80, backgroundColor:'white'}}>
</View>
</ScrollView>
<TouchableOpacity onPress={() => this.props.navigator.pop()}
style={{position:'absolute', left:10, bottom:10, width:60, height:60, borderRadius:30,
backgroundColor:'rgba(38,38,38,0.4)'}}>
<Image style={{width:30, height:30, marginTop:15, marginLeft:15, tintColor:'rgba(255,255,255,0.7)'}} source={require('./img/back-512.png')}/>
</TouchableOpacity>
</View>
);
}
}