Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 2b08220

Browse files
committed
update
1 parent 64ba121 commit 2b08220

File tree

4 files changed

+20
-193
lines changed

4 files changed

+20
-193
lines changed

dog-app/Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@ homepage = "https://dioxuslabs.com"
99
documentation = "https://dioxuslabs.com"
1010
keywords = ["dom", "ui", "gui", "react", "wasm"]
1111

12-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
13-
1412
[dependencies]
15-
dioxus = { version = "0.3" }
16-
dioxus-desktop = { version = "0.3" }
13+
dioxus = "0.3"
14+
dioxus-desktop = "0.3"
1715
reqwest = { version = "0.11.8", features = ["json"] }
1816
serde = { version = "1.0.132", features = ["derive"] }
1917

20-
2118
[package.metadata.bundle]
2219
name = "Dog Search Engine"
2320
identifier = "com.jon.dogsearch"

dog-app/src/main.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ mod models;
99
fn main() {
1010
dioxus_desktop::launch_cfg(
1111
app,
12-
Config::default().with_window(WindowBuilder::new().with_maximized(true).with_title("Dog App")),
12+
Config::default().with_window(
13+
WindowBuilder::new()
14+
.with_maximized(true)
15+
.with_title("Dog App"),
16+
),
1317
)
1418
}
1519

1620
fn app(cx: Scope) -> Element {
1721
let selected_breed = use_state::<Option<String>>(cx, || None);
1822
let search_input = use_state(cx, String::new);
1923

20-
// when the component loads, we want to fetch the dog list
21-
let fut = use_future!(cx, |()| async move {
22-
list_all_breeds().await
23-
});
24+
// Fetch the dog list when the component mounts
25+
let fut = use_future!(cx, |()| async move { list_all_breeds().await });
2426

2527
render!(
2628
link {
@@ -41,8 +43,7 @@ fn app(cx: Scope) -> Element {
4143
}
4244
}
4345
div { class: "px-2 flex",
44-
div {
45-
class: "grow w-full",
46+
div { class: "grow w-full h-full",
4647
if let Some(Ok(breeds)) = fut.value() {
4748
let current_search = search_input.get();
4849
rsx!{
@@ -56,7 +57,7 @@ fn app(cx: Scope) -> Element {
5657
}
5758
})
5859
};
59-
60+
6061
Some(rsx! {
6162
Card {
6263
key: "{breed}",
@@ -77,7 +78,7 @@ fn app(cx: Scope) -> Element {
7778
if let Some(selected_breed) = selected_breed.get() {
7879
rsx!(
7980
div {
80-
class: "grow-[1]",
81+
class: "w-1/2",
8182
img {
8283
src: "{selected_breed}"
8384
}
@@ -96,17 +97,13 @@ fn Card<'a>(cx: Scope, title: String, list: Vec<String>, onclick: EventHandler<'
9697
div {
9798
onclick: |_| onclick.call(()),
9899
class: "my-2 bg-gray-100 w-full rounded-sm p-2",
99-
h3 {
100-
class: "text-2xl",
101-
"{title}"
102-
}
103-
ul {
104-
class: "list-disc ml-8",
100+
h3 { class: "text-2xl", "{title}" }
101+
ul { class: "list-disc ml-8",
105102
{list.iter().map(|item| rsx!( li {
106103
key: "{item}",
107104
"{item}"
108105
}))}
109106
}
110107
}
111108
)
112-
}
109+
}

dog-app/src/models.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
1-
// List all breeds
2-
// Random image
3-
// By breed
4-
// By sub-breed
5-
// Browse breed list
6-
71
#![allow(non_snake_case)]
8-
use std::collections::HashMap;
92
use serde::{Deserialize, Serialize};
3+
use std::collections::HashMap;
104

115
#[derive(Serialize, Deserialize)]
126
pub struct AllBreeds {
137
pub message: HashMap<String, Vec<String>>,
148
pub status: String,
159
}
1610

17-
1811
pub async fn list_all_breeds() -> reqwest::Result<AllBreeds> {
1912
reqwest::get("https://dog.ceo/api/breeds/list/all")
20-
.await
21-
?
13+
.await?
2214
.json::<AllBreeds>()
2315
.await
2416
}
@@ -29,13 +21,9 @@ pub struct RandomImageByBreed {
2921
pub status: String,
3022
}
3123

32-
3324
pub async fn random_image_by_breed(breed: &str) -> reqwest::Result<RandomImageByBreed> {
3425
reqwest::get(format!("https://dog.ceo/api/breed/{breed}/images/random"))
35-
.await
36-
?
37-
.json::<RandomImageByBreed>()
38-
.await
26+
.await?
27+
.json::<RandomImageByBreed>()
28+
.await
3929
}
40-
41-

dog-app/src/old.rs

Lines changed: 0 additions & 155 deletions
This file was deleted.

0 commit comments

Comments
 (0)