Skip to content

Commit

Permalink
fix: Fix git checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed Sep 1, 2024
1 parent 8a6559a commit b399249
Show file tree
Hide file tree
Showing 16 changed files with 793 additions and 190 deletions.
810 changes: 709 additions & 101 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ edition = "2021"
build = "build.rs"

[dependencies]
dioxus-web = { version = "0.4" }
dioxus = { version = "0.4" }
dioxus-router = { version = "0.4.1", features = ["web"] }
dioxus = { version = "0.5", features = ["web"] }
dioxus-router = { version = "0.5", features = ["web"] }
log = "0.4.19"
dioxus-logger = "0.4.1"
console_error_panic_hook = "0.1.7"
Expand Down
2 changes: 1 addition & 1 deletion public/tailwind.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/components/guide_card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use dioxus_router::prelude::*;
use crate::models::Guide;

#[allow(non_snake_case)]
#[inline_props]
pub fn GuideCard<'a>(cx: Scope, guide: &'a Guide) -> Element {
render! {
#[component]
pub fn GuideCard(guide: &'static Guide) -> Element {
rsx!(
div { class: "text-white p-4 bg-blue-1 rounded-md",
table { class: "text-left [&_th]:pr-4",
tr {
Expand All @@ -25,5 +25,5 @@ pub fn GuideCard<'a>(cx: Scope, guide: &'a Guide) -> Element {
}
}
}
}
)
}
10 changes: 5 additions & 5 deletions src/components/guide_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use crate::models::Guide;
use crate::components::GuideCard;

#[allow(non_snake_case)]
#[inline_props]
pub fn GuideGrid<'a>(cx: Scope, guides: &'a [Guide]) -> Element {
render! {
#[component]
pub fn GuideGrid(guides: &'static [Guide]) -> Element {
rsx!(
div { class: "grid grid-cols-1 lg:grid-cols-2 gap-4",
for guide in guides {
GuideCard { key: "{guide.name}", guide: guide }
GuideCard { key: "{guide.name}", guide }
}
}
}
)
}
8 changes: 4 additions & 4 deletions src/components/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use crate::Route;
use crate::components::Navigation;

#[allow(non_snake_case)]
#[inline_props]
pub fn Layout(cx: Scope) -> Element {
render! {
#[component]
pub fn Layout() -> Element {
rsx!(
header { class: "w-full p-8 flex flex-col",
span { class: "mx-auto text-white pb-8", "D I O X U S - C O M M U N I T Y" }
Navigation {}
}
main { class: "w-full p-8 pt-0 flex flex-col", Outlet::<Route> {} }
}
)
}
20 changes: 9 additions & 11 deletions src/components/navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,34 @@ use dioxus::prelude::*;
use dioxus_router::prelude::*;
use crate::Route;

#[derive(Props)]
struct NavigationLinkProps<'a> {
pub label: &'a str,
#[derive(Props, Clone, PartialEq)]
struct NavigationLinkProps {
pub label: String,
/// Same as the corresponding [`LinkProps`](https://docs.rs/dioxus-router/latest/dioxus_router/components/struct.LinkProps.html) property.
#[props(into)]
pub to: IntoRoutable,
}

#[allow(non_snake_case)]
fn NavigationLink<'a>(cx: Scope<'a, NavigationLinkProps<'static>>) -> Element<'a> {
let NavigationLinkProps { to, label } = cx.props;

render! {
fn NavigationLink(NavigationLinkProps { to, label }: NavigationLinkProps) -> Element {
rsx!(
Link {
active_class: "bg-blue-2",
class: "p-1 px-4 justify-center grow flex text-white hover:border-transparent hover:bg-blue-2 border-2 border-blue-2 rounded-md md:rounded-full transition ease-in-out delay-30",
to: to.clone(),
"{label}"
}
}
)
}

#[allow(non_snake_case)]
pub fn Navigation(cx: Scope) -> Element {
render! {
pub fn Navigation() -> Element {
rsx!(
nav { class: "mx-auto p-2 flex flex-wrap bg-blue-1 rounded-md md:rounded-full gap-2",
NavigationLink { to: Route::Home {}, label: "Home" }
NavigationLink { to: "https://github.com/dioxus-community", label: "GitHub" }
NavigationLink { to: Route::OurProjects {}, label: "Our projects" }
NavigationLink { to: Route::Guides {}, label: "Guides" }
}
}
)
}
62 changes: 29 additions & 33 deletions src/components/project_card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const STARGAZERS_PROPERTY_PATTERN: &str = "\"stargazers_count\":";
/// - `insert_stars` - Will insert GitHub stars if the project has a `None` `star_count` property and a `Some(_)` `repository_url` property.
/// If the repository URL is not a GitHub repository, this will fail.
#[allow(non_snake_case)]
#[inline_props]
pub fn ProjectCard<'a>(cx: Scope, project: &'a Project<'a>, insert_stars: bool) -> Element {
render! {
#[component]
pub fn ProjectCard(project: &'static Project<'static>, insert_stars: bool) -> Element {
rsx!(
div { class: "text-white p-4 bg-blue-1 rounded-md",
table { class: "text-left [&_th]:pr-4",
tr {
Expand All @@ -26,49 +26,41 @@ pub fn ProjectCard<'a>(cx: Scope, project: &'a Project<'a>, insert_stars: bool)
td { "{project.status}" }
}
if let Some(description) = &project.description {
rsx! {
tr {
th { "📜 Description" }
td { "{description}" }
}
tr {
th { "📜 Description" }
td { "{description}" }
}
}
if let Some(repository_url) = &project.repository_url {
rsx! {
tr {
th { "💾 Repository" }
td { Link { class: "underline", to: "{repository_url}", "{repository_url}" } }
}
tr {
th { "💾 Repository" }
td { Link { class: "underline", to: "{repository_url}", "{repository_url}" } }
}
}
if let Some(website) = &project.website {
if !website.is_empty() {
rsx! {
tr {
th { "🌐 Website" }
td { Link { class: "underline", to: "{website}", "{website}" } }
}
tr {
th { "🌐 Website" }
td { Link { class: "underline", to: "{website}", "{website}" } }
}
} else {
rsx! { "" }
}
}
Stars { project: project, insert_stars: *insert_stars }
Stars { project, insert_stars }
}
}
}
)
}

#[allow(non_snake_case)]
#[inline_props]
fn Stars<'a>(cx: Scope, project: &'a Project<'a>, insert_stars: bool) -> Element {
#[component]
fn Stars(project: &'static Project<'static>, insert_stars: bool) -> Element {
if let Some(star_count) = project.star_count {
return render! {
return rsx!(
tr {
th { "⭐ Stars" }
td { "{star_count}" }
}
};
);
}

let empty_star_row = rsx! {
Expand All @@ -79,28 +71,32 @@ fn Stars<'a>(cx: Scope, project: &'a Project<'a>, insert_stars: bool) -> Element
};

if !insert_stars {
return cx.render(empty_star_row);
return empty_star_row;
};

let Some(repository_url) = &project.repository_url else {
return cx.render(empty_star_row);
return empty_star_row;
};

let fetched_stars = use_future(cx, &repository_url.to_string(), fetch_star_count);
let fetched_stars = use_resource(use_reactive(&repository_url.to_owned(), |repository_url| {
fetch_star_count(repository_url.as_ref().to_owned())
}));

let fetched_stars = &*fetched_stars.read();

match fetched_stars.value() {
Some(Ok(star_count)) => render! {
match fetched_stars {
Some(Ok(star_count)) => rsx!(
tr {
th { "⭐ Stars" }
td { "{star_count}" }
}
},
),
Some(Err(e)) => {
log::error!("couldn't fetch stars from repository \"{repository_url}\". Error: {e}");

None
}
None => cx.render(empty_star_row),
None => empty_star_row
}
}

Expand Down
Loading

0 comments on commit b399249

Please sign in to comment.