@@ -5,16 +5,17 @@ use leptos::{
5
5
use serde:: { Deserialize , Serialize } ;
6
6
7
7
use crate :: components:: ContributorCard ;
8
+ use crate :: { error, log} ;
8
9
9
- #[ derive( Clone , PartialEq , Eq , Serialize , Deserialize ) ]
10
+ #[ derive( Clone , Debug , PartialEq , Eq , Serialize , Deserialize ) ]
10
11
pub struct Contributor {
11
12
login : String ,
12
13
avatar_url : String ,
13
14
html_url : String ,
14
15
bio : Option < String > ,
15
16
twitter_username : Option < String > ,
16
17
location : Option < String > ,
17
- contributions : i32 ,
18
+ contributions : Option < i32 > ,
18
19
}
19
20
20
21
async fn fetch_contributors ( ) -> Result < Vec < Contributor > > {
@@ -26,28 +27,30 @@ async fn fetch_contributors() -> Result<Vec<Contributor>> {
26
27
. json :: < Vec < Contributor > > ( )
27
28
. await ?;
28
29
29
- let response = join_all (
30
- response
31
- . into_iter ( )
32
- . map ( |contributor| fetch_contributor_info ( contributor. login ) ) ,
33
- )
34
- . await ;
35
-
36
- let response = response
37
- . into_iter ( )
38
- . filter_map ( std:: result:: Result :: ok)
30
+ let response = join_all ( response. iter ( ) . map ( |c| fetch_contributor_info ( c) ) )
31
+ . await
32
+ . iter ( )
33
+ . flat_map ( |c| c. clone ( ) . ok ( ) )
39
34
. collect :: < Vec < Contributor > > ( ) ;
40
35
41
36
Ok ( response)
42
37
}
43
38
44
- async fn fetch_contributor_info ( username : String ) -> Result < Contributor > {
45
- let response = reqwasm:: http:: Request :: get ( & format ! ( "https://api.github.com/users/{username}" ) )
46
- . send ( )
47
- . await ?
48
- . json :: < Contributor > ( )
49
- . await ?;
50
- Ok ( response)
39
+ async fn fetch_contributor_info ( contributor : & Contributor ) -> Result < Contributor > {
40
+ Ok ( reqwasm:: http:: Request :: get ( & format ! (
41
+ "https://api.github.com/users/{}" ,
42
+ contributor. login
43
+ ) )
44
+ . send ( )
45
+ . await ?
46
+ . json :: < Contributor > ( )
47
+ . await
48
+ . inspect ( |c| log ! ( "{c:?} - {contributor:?}" ) )
49
+ . inspect_err ( |e| error ! ( "Error: {e:?}" ) )
50
+ . map ( |c| Contributor {
51
+ contributions : contributor. contributions ,
52
+ ..c
53
+ } ) ?)
51
54
}
52
55
53
56
#[ island]
@@ -62,14 +65,13 @@ pub fn Contributors() -> impl IntoView {
62
65
brand_src=item. avatar_url. clone( )
63
66
twitter=item. twitter_username. clone( )
64
67
location=item. location. clone( )
65
- contributions=item. contributions
68
+ contributions=item. contributions. unwrap_or ( 1 )
66
69
/>
67
70
}
68
71
} ;
69
72
70
73
let contributors_view = move || {
71
- let mut contributors = contributors_results. get ( ) ?. ok ( ) ?;
72
- contributors. sort_by_key ( |a| a. contributions ) ;
74
+ let contributors = contributors_results. get ( ) ?. ok ( ) ?;
73
75
let result = contributors
74
76
. iter ( )
75
77
. map ( contributorMapper)
0 commit comments