1
- use leptos:: * ;
1
+ use leptos:: { error:: Result , * } ;
2
+ use serde:: { Deserialize , Serialize } ;
2
3
3
4
use crate :: components:: { cards:: contributor_card:: ContributorCard , footer:: Footer , header:: Header } ;
4
5
5
- struct ContributorItem {
6
- name : & ' static str ,
7
- description : & ' static str ,
8
- link : & ' static str ,
9
- brand_src : & ' static str ,
6
+ #[ derive( Clone , PartialEq , Eq , Serialize , Deserialize ) ]
7
+ pub struct Contributor {
8
+ login : String ,
9
+ avatar_url : String ,
10
+ html_url : String ,
11
+ }
12
+
13
+ async fn fetch_contributors ( ) -> Result < Vec < Contributor > > {
14
+ let response = reqwasm:: http:: Request :: get (
15
+ "https://api.github.com/repos/RustLangES/rustlanges.github.io/contributors" ,
16
+ )
17
+ . send ( )
18
+ . await ?
19
+ . json :: < Vec < Contributor > > ( )
20
+ . await ?
21
+ . into_iter ( )
22
+ . collect ( ) ;
23
+ Ok ( response)
10
24
}
11
25
12
26
#[ component]
13
27
pub fn Contributors ( ) -> impl IntoView {
14
- let contributors: Vec < ContributorItem > = vec ! [
15
- ContributorItem {
16
- name: "Phosphorus Moscu" ,
17
- description: "Student in Computer Science degree at Universidad Nacional del Oeste | Developer Consultant at Globant" ,
18
- link: "https://github.com/Phosphorus-M" ,
19
- brand_src: "https://avatars.githubusercontent.com/u/19656993?v=4" ,
20
- } ,
21
- ContributorItem {
22
- name: "Sergio Alejandro Ribera Costa" ,
23
- description: "Enthusiastic developer Linux and Open Source lover" ,
24
- link: "https://github.com/SergioRibera" ,
25
- brand_src: "https://avatars.githubusercontent.com/u/56278796?v=4" ,
26
- } ,
27
- ContributorItem {
28
- name: "Michael Cardoza" ,
29
- description: "Software Developer" ,
30
- link: "https://github.com/michaelcardoza" ,
31
- brand_src: "https://avatars.githubusercontent.com/u/8800455?v=4" ,
32
- } ,
33
- ContributorItem {
34
- name: "Emilio Ruscitti" ,
35
- description: "Rust Dev" ,
36
- link: "https://github.com/Lemin-n" ,
37
- brand_src: "https://avatars.githubusercontent.com/u/88170949?v=4" ,
38
- } ,
39
- ContributorItem {
40
- name: "carbon based lifeform" ,
41
- description: "Rust Dev" ,
42
- link: "https://github.com/ph4un00b" ,
43
- brand_src: "https://avatars.githubusercontent.com/u/1057021?v=4" ,
44
- } ,
45
- ContributorItem {
46
- name: "CrawKatt" ,
47
- description: "Aprendiz de Rust, estudiante de AIEP, Chileno" ,
48
- link: "https://github.com/CrawKatt" ,
49
- brand_src: "https://avatars.githubusercontent.com/u/108593932?v=4" ,
50
- } ,
51
- ] ;
28
+ let contributors_results = create_local_resource ( move || ( ) , |_| fetch_contributors ( ) ) ;
29
+
30
+ let contributors_view = move || {
31
+ let data = contributors_results. read ( ) ;
32
+ let Some ( Ok ( items) ) = data else { return None } ;
33
+ let result = items
34
+ . iter ( )
35
+ . map ( |item| {
36
+ view ! {
37
+ <ContributorCard
38
+ name=item. login. clone( )
39
+ description=""
40
+ link=item. html_url. clone( )
41
+ brand_src=item. avatar_url. clone( )
42
+ />
43
+ }
44
+ } )
45
+ . collect :: < Fragment > ( ) ;
46
+ Some ( result. into_view ( ) )
47
+ } ;
52
48
53
49
view ! {
54
50
<div>
@@ -61,19 +57,7 @@ pub fn Contributors() -> impl IntoView {
61
57
<span class="font-alfa-slab text-orange-500" >"Colaboradores" </span>
62
58
</h2>
63
59
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 2xl:grid-cols-5 gap-6" >
64
- { contributors
65
- . into_iter( )
66
- . map( |contributor| {
67
- view! {
68
- <ContributorCard
69
- name=contributor. name
70
- description=contributor. description
71
- link=contributor. link
72
- brand_src=contributor. brand_src
73
- />
74
- }
75
- } )
76
- . collect:: <Vec <_>>( ) }
60
+ { contributors_view}
77
61
</div>
78
62
</div>
79
63
</section>
0 commit comments