-
Notifications
You must be signed in to change notification settings - Fork 427
/
Copy pathPersonPage.js
99 lines (88 loc) · 2.7 KB
/
PersonPage.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
import BasePersonPage from "./widget/BasePersonPage";
import userAction from "../store/actions/user";
import {Actions} from "react-native-router-flux";
import store from "../store";
const {dispatch, getState} = store;
/**
* 用户信息页面
*/
class PersonPage extends BasePersonPage {
constructor(props) {
super(props);
this._onClose = this._onClose.bind(this);
this._refreshInfo = this._refreshInfo.bind(this);
this.state = {
userInfo: {
login: this.props.currentUser,
followers: '---',
star: '---',
following: '---',
public_repos: '---',
},
needFollow: false,
hadFollowed: false,
}
}
componentDidMount() {
this._refreshInfo();
super.componentDidMount();
}
componentWillUnmount() {
}
_onClose() {
Actions.pop();
return true;
}
getUserInfo() {
return this.state.userInfo;
}
getNeedFollow() {
let login = getState()['user'].userInfo.login;
return this.state.needFollow && (this.props.currentUser !== login);
}
getHanFollow() {
return this.state.hadFollowed;
}
_refreshInfo() {
userAction.getPersonUserInfo(this.props.currentUser).then((res) => {
if (res && res.result) {
this.setState({
userInfo: res.data
});
if (res.data.type === "Organization") {
Actions.refresh({titleData: res.data, showType: "Organization"});
} else {
Actions.refresh({titleData: res.data, showType: "user"});
}
}
return res.next();
}).then((res) => {
if (res && res.result) {
this.setState({
userInfo: res.data
});
if (res.data.type === "Organization") {
Actions.refresh({titleData: res.data, showType: "Organization"});
} else {
Actions.refresh({titleData: res.data, showType: "user"});
}
}
});
userAction.checkFollow(this.props.currentUser).then((res) => {
this.setState({
hadFollowed: res.result,
needFollow: true
})
});
}
doFollowLogic() {
Actions.LoadingModal({backExit: false});
userAction.doFollow(this.props.currentUser, !this.state.hadFollowed).then(() => {
this._refreshInfo();
setTimeout(() => {
Actions.pop();
}, 500);
})
}
}
export default PersonPage