Skip to content

Commit 8e83eaf

Browse files
authored
fix: Update examples (#29)
* fix: Update launch function in clipboard example * fix: Update launch function in geolocation example * fixes everywhere * fix
1 parent 74d9eaa commit 8e83eaf

File tree

12 files changed

+60
-59
lines changed

12 files changed

+60
-59
lines changed

Cargo.toml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
[workspace]
2-
resolver = "2"
3-
members = [
4-
"std",
5-
"examples/*",
6-
]
7-
8-
[workspace.dependencies]
9-
dioxus-std = { path = "./std" }
10-
dioxus = { version = "0.5" }
11-
dioxus-web = { version = "0.5" }
12-
dioxus-desktop = { version = "0.5" }
1+
[workspace]
2+
resolver = "2"
3+
members = [
4+
"std",
5+
"examples/*",
6+
]
7+
8+
[workspace.dependencies]
9+
dioxus-std = { path = "./std" }
10+
dioxus = { version = "0.5" }

examples/channel/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
dioxus-std = { workspace = true, features = ["utils"]}
8-
dioxus = { workspace = true }
9-
dioxus-web = { workspace = true }
8+
dioxus = { workspace = true, features = ["web"]}
109

1110
log = "0.4.6"
1211

examples/channel/src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ fn app() -> Element {
1919
}
2020
});
2121

22-
let send = move |_: MouseEvent| async move {
23-
channel.send("Hello").await.ok();
22+
let send = move |_: MouseEvent| {
23+
to_owned![channel];
24+
async move {
25+
channel.send("Hello").await.ok();
26+
}
2427
};
2528

2629
rsx!(

examples/clipboard/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ edition = "2021"
55

66
[dependencies]
77
dioxus-std = { workspace = true, features = ["clipboard"] }
8-
dioxus = { workspace = true }
9-
dioxus-desktop = { workspace = true }
8+
dioxus = { workspace = true, features = ["desktop"]}

examples/clipboard/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ use dioxus::prelude::*;
22
use dioxus_std::clipboard::use_clipboard;
33

44
fn main() {
5-
dioxus_desktop::launch(app);
5+
launch(app);
66
}
77

88
fn app() -> Element {
99
let mut clipboard = use_clipboard();
1010
let mut text = use_signal(String::new);
1111

1212
let oninput = move |e: FormEvent| {
13-
text.set(e.data.value.clone());
13+
text.set(e.data.value());
1414
};
1515

1616
let oncopy = move |_| match clipboard.set(text.read().clone()) {

examples/color_scheme/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
dioxus-std = { workspace = true, features = ["color_scheme"] }
8-
dioxus = { workspace = true }
9-
dioxus-web = { workspace = true }
8+
dioxus = { workspace = true, features = ["web"]}
109

1110
log = "0.4.6"
1211

examples/color_scheme/src/main.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn main() {
66
wasm_logger::init(wasm_logger::Config::default());
77
console_error_panic_hook::set_once();
88

9-
dioxus_web::launch(app);
9+
launch(app);
1010
}
1111

1212
fn app() -> Element {
@@ -17,13 +17,9 @@ fn app() -> Element {
1717
style: "text-align: center;",
1818
h1 { "🌗 Dioxus 🚀" }
1919
if let Ok(color_scheme) = color_scheme {
20-
rsx!(
21-
h3 { "You preferred color scheme is {color_scheme:?}." }
22-
)
20+
h3 { "You preferred color scheme is {color_scheme:?}." }
2321
} else {
24-
rsx!(
25-
h3 { "There was an error when reading your preferred color scheme."}
26-
)
22+
h3 { "There was an error when reading your preferred color scheme."}
2723
}
2824
}
2925
)

examples/geolocation/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ edition = "2021"
55

66
[dependencies]
77
dioxus-std = { workspace = true, features = ["geolocation"] }
8-
dioxus = { workspace = true }
9-
dioxus-desktop ={ workspace = true }
10-
# dioxus-web ={ workspace = true }
8+
# You can change from 'desktop' to 'web' as well
9+
dioxus = { workspace = true, features = ["desktop"] }

examples/geolocation/src/main.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@ use dioxus::prelude::*;
22
use dioxus_std::geolocation::{init_geolocator, use_geolocation, PowerMode};
33

44
fn main() {
5-
dioxus_desktop::launch(app);
6-
//dioxus_web::launch(app);
5+
launch(app);
76
}
87

98
fn app() -> Element {
10-
let geolocator = init_geolocator(PowerMode::High).unwrap();
11-
let initial_coords = use_future(|_| async move { geolocator.get_coordinates().await.unwrap() });
9+
let geolocator = init_geolocator(PowerMode::High);
10+
let initial_coords = use_resource(move || async move {
11+
geolocator
12+
.read()
13+
.as_ref()
14+
.unwrap()
15+
.get_coordinates()
16+
.await
17+
.unwrap()
18+
});
1219
let latest_coords = use_geolocation();
1320

1421
let latest_coords = match latest_coords {
@@ -22,24 +29,22 @@ fn app() -> Element {
2229
// Google maps embed api key
2330
//let key = std::env::var("DIOXUS_GEOLOCATION_MAP_KEY").unwrap();
2431

25-
let initial_coords = initial_coords.value();
26-
2732
rsx!(
2833
div {
2934
style: "text-align: center;",
3035
h1 { "🗺️ Dioxus Geolocation Example 🛰️" }
3136
h3 { "Your initial location is:"}
3237

3338
p {
34-
if let Some(coords) = initial_coords {
35-
format!("Latitude: {} | Longitude: {}", coords.latitude, coords.longitude)
39+
if let Some(coords) = initial_coords.read().as_ref() {
40+
"Latitude: {coords.latitude} | Longitude: {coords.longitude}"
3641
} else {
37-
"Loading...".to_string()
42+
"Loading..."
3843
}
3944
}
4045

4146
h3 { "Your latest location is:" }
42-
p { format!("Latitude: {} | Longitude: {}", latest_coords.latitude, latest_coords.longitude) }
47+
p { "Latitude: {latest_coords.latitude} | Longitude: {latest_coords.longitude}" }
4348

4449
// Google maps embed
4550
//iframe {

examples/i18n/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
dioxus-std = { workspace = true, features = ["i18n"] }
8-
dioxus = { workspace = true }
9-
dioxus-web = { workspace = true }
8+
dioxus = { workspace = true, features = ["web"] }
109

1110
log = "0.4.6"
1211

0 commit comments

Comments
 (0)