forked from ghuser-io/ghuser.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProfile.js
85 lines (77 loc) · 2.61 KB
/
Profile.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
import React from 'react';
import Content from '../Content';
import NavBar from '../NavBar';
import PageContent from '../PageContent';
import '../All.css';
import LeftPanel from './leftpanel/LeftPanel';
import RightPanel from './rightpanel/RightPanel';
import './Profile.css';
import * as db from './db';
import {urls} from '../../ghuser';
class Profile extends React.Component {
constructor(props) {
super(props);
this.state = {
loading: true,
user: {
login: props.username
},
contribs: null,
profilesBeingCreated: []
};
}
async componentDidMount() {
const userId = this.props.username.toLowerCase();
try {
const userData = await fetch(`${db.url}/users/${userId}.json`);
const user = await userData.json();
this.setState({ user });
const contribsData = await fetch(`${db.url}/contribs/${userId}.json`);
const contribs = await contribsData.json();
this.setState({ contribs });
} catch (_) {
// This profile doesn't exist yet, let's see if it's being created:
const profilesBeingCreatedData = await fetch(urls.profileQueueEndpoint);
const profilesBeingCreated = await profilesBeingCreatedData.json();
this.setState({ profilesBeingCreated });
for (const profile of profilesBeingCreated) {
if (profile.login.toLowerCase() === userId) { // profile is being created
this.setState({
user: {
...this.state.user,
avatar_url: profile.avatar_url,
ghuser_being_created: true
}
});
break;
}
}
}
this.setState({ loading: false });
}
render() {
const content = this.state.loading &&
<div><i className="fas fa-spinner fa-pulse"></i> {this.state.user.login}'s profile</div> ||
<div className="row">
<LeftPanel user={this.state.user} contribs={this.state.contribs}
orgs={this.props.orgs} />
<RightPanel username={this.state.user.login}
fetchedat={this.state.user.contribs && this.state.user.contribs.fetched_at}
contribs={this.state.contribs}
being_created={this.state.user.ghuser_being_created}
deleted_because={this.state.user.ghuser_deleted_because}
profilesBeingCreated={this.state.profilesBeingCreated} />
</div>;
return (
<PageContent>
<NavBar/>
<Content>
<div className="container container-lg mt-2">
{ content }
</div>
</Content>
</PageContent>
);
}
}
export default Profile;