Skip to content

Commit 3975de6

Browse files
committed
refactor: improve the fetching of contributors
1 parent 1f6d097 commit 3975de6

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

src/app.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn App() -> impl IntoView {
1111
view! {
1212
<Router>
1313
<Routes>
14-
<Route path="" view=|| view! { <Index/> }/>
14+
<Route path="/" view=|| view! { <Index/> }/>
1515
<Route path="/colaboradores" view=|| view! { <Contributors/> }/>
1616
</Routes>
1717
</Router>

src/components/header.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn Header() -> impl IntoView {
1111
<header class="border-b border-b-black/20">
1212
<div class="container mx-auto px-4 flex items-center justify-between flex-col lg:flex-row">
1313
<div class="flex justify-between w-full lg:w-auto">
14-
<A href="https://rustlanges.github.io/" exact=true class="flex items-center gap-x-4">
14+
<A href="/" exact=true class="flex items-center gap-x-4">
1515
<img
1616
src="https://www.rust-lang.org/static/images/rust-logo-blk.svg"
1717
class="max-h-20 rounded-full"

src/pages/contributors.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@ async fn fetch_contributors() -> Result<Vec<Contributor>> {
2626
#[component]
2727
pub fn Contributors() -> impl IntoView {
2828
let contributors_results = create_local_resource(move || (), |_| fetch_contributors());
29+
let contributorMapper = |item: &Contributor| {
30+
view! {
31+
<ContributorCard
32+
name=item.login.clone()
33+
description=""
34+
link=item.html_url.clone()
35+
brand_src=item.avatar_url.clone()
36+
/>
37+
}
38+
};
2939

3040
let contributors_view = move || {
31-
let data = contributors_results.get();
32-
let Some(Ok(items)) = data else { return None };
33-
let result = items
41+
let contributors = contributors_results.get()?.ok()?;
42+
let result = contributors
3443
.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-
})
44+
.map(contributorMapper)
4545
.collect::<Fragment>();
4646
Some(result.into_view())
4747
};

0 commit comments

Comments
 (0)