@@ -9,6 +9,7 @@ async function getUser(username) {
9
9
const { data } = await axios . get ( APIURL + username ) ;
10
10
createUserCard ( data , username ) ;
11
11
getRepos ( username ) ;
12
+ getEvents ( username ) ;
12
13
} catch ( err ) {
13
14
if ( err . response . status === 404 ) {
14
15
createErrorCard ( 'No profile with this username' ) ;
@@ -25,6 +26,15 @@ async function getRepos(username) {
25
26
}
26
27
}
27
28
29
+ async function getEvents ( username ) {
30
+ try {
31
+ const { data } = await axios . get ( APIURL + username + '/events' ) ;
32
+ addEventsToCard ( data ) ;
33
+ } catch ( err ) {
34
+ showEventError ( 'Problem fetching activity' ) ;
35
+ }
36
+ }
37
+
28
38
function createUserCard ( user , username ) {
29
39
const cardHTML = `
30
40
<div class="card">
@@ -44,6 +54,7 @@ function createUserCard(user, username) {
44
54
</ul>
45
55
46
56
<div id="repos"></div>
57
+ <div id="events" class="events"></div>
47
58
</div>
48
59
</div>` ;
49
60
main . innerHTML = cardHTML ;
@@ -68,9 +79,30 @@ function addReposToCard(repos) {
68
79
repoEl . href = repo . html_url ;
69
80
repoEl . target = '_blank' ;
70
81
repoEl . innerText = repo . name ;
71
-
82
+
72
83
reposEl . appendChild ( repoEl ) ;
73
- } ) ;
84
+ } ) ;
85
+ }
86
+
87
+ function addEventsToCard ( events ) {
88
+ const eventsEl = document . getElementById ( 'events' ) ;
89
+ if ( ! events . length ) {
90
+ eventsEl . innerHTML = '<p>No recent public activity</p>' ;
91
+ return ;
92
+ }
93
+
94
+ const list = document . createElement ( 'ul' ) ;
95
+ events . slice ( 0 , 5 ) . forEach ( ev => {
96
+ const item = document . createElement ( 'li' ) ;
97
+ item . innerText = `${ ev . type } - ${ ev . repo . name } ` ;
98
+ list . appendChild ( item ) ;
99
+ } ) ;
100
+ eventsEl . appendChild ( list ) ;
101
+ }
102
+
103
+ function showEventError ( msg ) {
104
+ const eventsEl = document . getElementById ( 'events' ) ;
105
+ eventsEl . innerHTML = `<p>${ msg } </p>` ;
74
106
}
75
107
76
108
form . addEventListener ( 'submit' , ( e ) => {
0 commit comments