Skip to content

Commit f80f982

Browse files
committedFeb 20, 2024
feat: add badge for contributions
1 parent a415b0c commit f80f982

File tree

5 files changed

+37
-15
lines changed

5 files changed

+37
-15
lines changed
 

‎flake.nix

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
toolchain
150150
trunk
151151
cargo-leptos
152+
binaryen
152153
];
153154
};
154155
};

‎input.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020

2121
.group:hover > span.badge-container {
22-
@apply first:min-w-28 first:min-h-6 items-center justify-center transition-all transform duration-1000;
22+
@apply first:min-h-6 items-center justify-center transition-all transform duration-1000;
2323
}
2424

2525
.group:hover > span.badge-container > span.badge-content {
@@ -42,4 +42,4 @@
4242
position: relative;
4343
width: 100%;
4444
height: auto;
45-
}
45+
}

‎src/components/aprende/books.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn Books(
1818
<div class="flex flex-col md:flex-row justify-center items-center container mx-auto mb-16 md:mb-28 gap-4">
1919
<section class="w-full md:w-1/2 px-10">
2020
<div class="relative group flex flex-col gap-y-6 border border-black p-2 sm:p-6 bg-orange-100 drop-shadow-[0_0_0_rgba(0,0,0)] hover:drop-shadow-[-4px_-4px_0_rgba(0,0,0)] justify-between group transition-all transform">
21-
<span class="absolute top-0 end-0 inline-flex items-center size-3.5 rounded-full border-2 border-white text-xs font-medium transition-all transform -translate-y-1/2 translate-x-1/2 bg-teal-500 dark:border-slate-900 badge-container">
21+
<span class="absolute top-0 end-0 inline-flex items-center size-3.5 group-hover:min-w-28 rounded-full border-2 border-white text-xs font-medium transition-all transform -translate-y-1/2 translate-x-1/2 bg-teal-500 dark:border-slate-900 badge-container">
2222
<span class="sr-only text-black badge-content transition-all transform ">
2323
"Recomendado"
2424
</span>
@@ -39,7 +39,7 @@ pub fn Books(
3939

4040
<section class="w-full md:w-1/2 px-10 flex flex-col h-full ">
4141
<div class="group flex flex-col gap-y-6 border border-black p-2 sm:p-6 bg-orange-100 drop-shadow-[0_0_0_rgba(0,0,0)] hover:drop-shadow-[-4px_-4px_0_rgba(0,0,0)] transition justify-between">
42-
<span class="absolute top-0 end-0 inline-flex items-center size-3.5 rounded-full border-2 border-white text-xs font-medium transition-all transform -translate-y-1/2 translate-x-1/2 bg-yellow-500 dark:border-slate-900 badge-container">
42+
<span class="absolute top-0 end-0 inline-flex items-center size-3.5 group-hover:min-w-28 rounded-full border-2 border-white text-xs font-medium transition-all transform -translate-y-1/2 translate-x-1/2 bg-yellow-500 dark:border-slate-900 badge-container">
4343
<span class="sr-only text-black badge-content transition-all transform ">
4444
"¡En Progreso!"
4545
</span>
@@ -93,4 +93,4 @@ pub fn Books(
9393
</div>
9494
</section>
9595
}
96-
}
96+
}

‎src/components/cards/contributor_card.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub fn ContributorCard(
1010
#[prop(into)] location: Option<String>,
1111
#[prop(into)] link: String,
1212
#[prop(into)] brand_src: String,
13+
#[prop(into)] contributions: i32,
1314
) -> impl IntoView {
1415

1516
view! {
@@ -19,6 +20,9 @@ pub fn ContributorCard(
1920
target="_blank"
2021
class="group flex flex-col gap-y-6 border border-black p-4 hover:bg-orange-500 bg-orange-100 drop-shadow-[0_0_0_rgba(0,0,0)] hover:drop-shadow-[-4px_-4px_0_rgba(0,0,0)] transition justify-between h-full"
2122
>
23+
<span class="absolute top-0 end-0 inline-flex items-center size-3.5 group-hover:min-w-16 rounded-full border-2 border-white text-xs font-medium transition-all transform -translate-y-1/2 translate-x-1/2 bg-teal-500 dark:border-slate-900 badge-container">
24+
<span class="sr-only text-black badge-content transition-all transform">{contributions}</span>
25+
</span>
2226
<div class="flex flex-col gap-y-2">
2327
<img src=brand_src width="60" class="rounded-full mb-4" alt=name.clone()/>
2428
<h2 class="font-work-sans text-black text-xl">{name}</h2>
@@ -61,4 +65,4 @@ pub fn ContributorCard(
6165
</a>
6266
</article>
6367
}
64-
}
68+
}

‎src/pages/contributors.rs

+26-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
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+
};
35
use serde::{Deserialize, Serialize};
46

57
use crate::components::ContributorCard;
68

7-
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
9+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
810
pub struct Contributor {
911
login: String,
1012
avatar_url: String,
1113
html_url: String,
1214
bio: Option<String>,
1315
twitter_username: Option<String>,
1416
location: Option<String>,
17+
contributions: i32,
1518
}
1619

1720
async fn fetch_contributors() -> Result<Vec<Contributor>> {
@@ -27,7 +30,8 @@ async fn fetch_contributors() -> Result<Vec<Contributor>> {
2730
response
2831
.into_iter()
2932
.map(|contributor| fetch_contributor_info(contributor.login)),
30-
).await;
33+
)
34+
.await;
3135

3236
let response = response
3337
.into_iter()
@@ -39,17 +43,18 @@ async fn fetch_contributors() -> Result<Vec<Contributor>> {
3943

4044
async fn fetch_contributor_info(username: String) -> Result<Contributor> {
4145
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?;
4650
Ok(response)
4751
}
4852

4953
#[island]
5054
pub fn Contributors() -> impl IntoView {
5155
let contributors_results = create_local_resource(move || (), |()| fetch_contributors());
5256
let contributorMapper = |item: &Contributor| {
57+
println!("Contributor: {item:?}");
5358
view! {
5459
<ContributorCard
5560
name=item.login.clone()
@@ -58,12 +63,14 @@ pub fn Contributors() -> impl IntoView {
5863
brand_src=item.avatar_url.clone()
5964
twitter=item.twitter_username.clone()
6065
location=item.location.clone()
66+
contributions=item.contributions
6167
/>
6268
}
6369
};
6470

6571
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);
6774
let result = contributors
6875
.iter()
6976
.map(contributorMapper)
@@ -79,9 +86,19 @@ pub fn Contributors() -> impl IntoView {
7986
<span class="font-alfa-slab text-orange-500">"Colaboradores"</span>
8087
</h2>
8188
<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+
/>
8298
{contributors_view}
8399
</div>
84100
</div>
85101
</section>
86102
}
87-
}
103+
}
104+

0 commit comments

Comments
 (0)