1
1
use futures:: future:: join_all;
2
- use leptos:: { error:: Result , Fragment , IntoView , SignalGet , create_local_resource, island, serde, view} ;
2
+ use leptos:: {
3
+ create_local_resource, error:: Result , island, serde, view, Fragment , IntoView , SignalGet ,
4
+ } ;
3
5
use serde:: { Deserialize , Serialize } ;
4
6
5
7
use crate :: components:: ContributorCard ;
6
8
7
- #[ derive( Clone , PartialEq , Eq , Serialize , Deserialize ) ]
9
+ #[ derive( Clone , Debug , PartialEq , Eq , Serialize , Deserialize ) ]
8
10
pub struct Contributor {
9
11
login : String ,
10
12
avatar_url : String ,
11
13
html_url : String ,
12
14
bio : Option < String > ,
13
15
twitter_username : Option < String > ,
14
16
location : Option < String > ,
17
+ contributions : i32 ,
15
18
}
16
19
17
20
async fn fetch_contributors ( ) -> Result < Vec < Contributor > > {
@@ -27,7 +30,8 @@ async fn fetch_contributors() -> Result<Vec<Contributor>> {
27
30
response
28
31
. into_iter ( )
29
32
. map ( |contributor| fetch_contributor_info ( contributor. login ) ) ,
30
- ) . await ;
33
+ )
34
+ . await ;
31
35
32
36
let response = response
33
37
. into_iter ( )
@@ -39,17 +43,18 @@ async fn fetch_contributors() -> Result<Vec<Contributor>> {
39
43
40
44
async fn fetch_contributor_info ( username : String ) -> Result < Contributor > {
41
45
let response = reqwasm:: http:: Request :: get ( & format ! ( "https://api.github.com/users/{username}" ) )
42
- . send ( )
43
- . await ?
44
- . json :: < Contributor > ( )
45
- . await ?;
46
+ . send ( )
47
+ . await ?
48
+ . json :: < Contributor > ( )
49
+ . await ?;
46
50
Ok ( response)
47
51
}
48
52
49
53
#[ island]
50
54
pub fn Contributors ( ) -> impl IntoView {
51
55
let contributors_results = create_local_resource ( move || ( ) , |( ) | fetch_contributors ( ) ) ;
52
56
let contributorMapper = |item : & Contributor | {
57
+ println ! ( "Contributor: {item:?}" ) ;
53
58
view ! {
54
59
<ContributorCard
55
60
name=item. login. clone( )
@@ -58,12 +63,14 @@ pub fn Contributors() -> impl IntoView {
58
63
brand_src=item. avatar_url. clone( )
59
64
twitter=item. twitter_username. clone( )
60
65
location=item. location. clone( )
66
+ contributions=item. contributions
61
67
/>
62
68
}
63
69
} ;
64
70
65
71
let contributors_view = move || {
66
- let contributors = contributors_results. get ( ) ?. ok ( ) ?;
72
+ let mut contributors = contributors_results. get ( ) ?. ok ( ) ?;
73
+ contributors. sort_by_key ( |a| a. contributions ) ;
67
74
let result = contributors
68
75
. iter ( )
69
76
. map ( contributorMapper)
@@ -79,9 +86,19 @@ pub fn Contributors() -> impl IntoView {
79
86
<span class="font-alfa-slab text-orange-500" >"Colaboradores" </span>
80
87
</h2>
81
88
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 2xl:grid-cols-5 gap-6" >
89
+ <ContributorCard
90
+ name="SergioRibera"
91
+ description=Some ( "Algo" . to_string( ) )
92
+ link="github.com/SergioRibera" . to_string( )
93
+ brand_src="" . to_string( )
94
+ twitter=Some ( "@sergioribera_rs" . to_string( ) )
95
+ location=Some ( "Bolivia" . to_string( ) )
96
+ contributions=50
97
+ />
82
98
{ contributors_view}
83
99
</div>
84
100
</div>
85
101
</section>
86
102
}
87
- }
103
+ }
104
+
0 commit comments