Skip to content

Commit 6905bf9

Browse files
committed
chore: clean up examples and fix link opening code
1 parent cc99fa8 commit 6905bf9

File tree

7 files changed

+28
-31
lines changed

7 files changed

+28
-31
lines changed

examples/disabled.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ fn app(cx: Scope) -> Element {
1818
disabled: "{disabled}",
1919
"lower button"
2020
}
21-
22-
input {
23-
value: "false",
24-
}
25-
2621
}
2722
})
2823
}

examples/dog_app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct ListBreeds {
1616
}
1717

1818
fn app(cx: Scope) -> Element {
19-
let fut = use_future(&cx, || async move {
19+
let breeds = use_future(&cx, || async move {
2020
reqwest::get("https://dog.ceo/api/breeds/list/all")
2121
.await
2222
.unwrap()
@@ -26,7 +26,7 @@ fn app(cx: Scope) -> Element {
2626

2727
let (breed, set_breed) = use_state(&cx, || None);
2828

29-
match fut.value() {
29+
match breeds.value() {
3030
Some(Ok(breeds)) => cx.render(rsx! {
3131
div {
3232
h1 {"Select a dog breed!"}

examples/file_explorer.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ fn app(cx: Scope) -> Element {
5656
)
5757
})
5858
}
59-
6059
})
6160
}
6261

examples/filedragdrop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ fn main() {
44
dioxus::desktop::launch_with_props(app, (), |c| {
55
c.with_file_drop_handler(|_w, e| {
66
println!("{:?}", e);
7-
false
7+
true
88
})
99
});
1010
}

examples/framework_benchmark.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ impl Label {
1717
fn new_list(num: usize) -> Vec<Self> {
1818
let mut rng = SmallRng::from_entropy();
1919
let mut labels = Vec::with_capacity(num);
20-
for _ in 0..num {
20+
for x in 0..num {
2121
labels.push(Label {
22-
key: 0,
22+
key: x,
2323
labels: [
2424
ADJECTIVES.choose(&mut rng).unwrap(),
2525
COLOURS.choose(&mut rng).unwrap(),

packages/desktop/src/interpreter.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -200,40 +200,42 @@ export class Interpreter {
200200
let target = event.target;
201201
if (target != null) {
202202
let realId = target.getAttribute(`data-dioxus-id`);
203+
let shouldPreventDefault = target.getAttribute(
204+
`dioxus-prevent-default`
205+
);
206+
207+
if (event.type == "click") {
208+
event.preventDefault();
209+
if (shouldPreventDefault !== `onclick`) {
210+
console.log("click", event);
211+
console.log("clickeded", event.target);
212+
console.log("clickeded", event.target.tagName);
213+
if (target.tagName == "A") {
214+
const href = target.getAttribute("href");
215+
if (href !== "" && href !== null && href !== undefined) {
216+
window.rpc.call("browser_open", { href });
217+
}
218+
}
219+
}
220+
}
221+
203222
// walk the tree to find the real element
204223
while (realId == null && target.parentElement != null) {
205224
target = target.parentElement;
206225
realId = target.getAttribute(`data-dioxus-id`);
207226
}
208-
const shouldPreventDefault = target.getAttribute(
227+
228+
shouldPreventDefault = target.getAttribute(
209229
`dioxus-prevent-default`
210230
);
231+
211232
let contents = serialize_event(event);
212233
if (shouldPreventDefault === `on${event.type}`) {
213234
event.preventDefault();
214235
}
215236
if (event.type == "submit") {
216237
event.preventDefault();
217238
}
218-
if (event.type == "click") {
219-
event.preventDefault();
220-
if (shouldPreventDefault !== `onclick`) {
221-
if (target.tagName == "A") {
222-
const href = target.getAttribute("href");
223-
if (
224-
href !== "" &&
225-
href !== null &&
226-
href !== undefined &&
227-
realId != null
228-
) {
229-
window.rpc.call("browser_open", {
230-
mounted_dom_id: parseInt(realId),
231-
href,
232-
});
233-
}
234-
}
235-
}
236-
}
237239
if (realId == null) {
238240
return;
239241
}

packages/desktop/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ pub fn launch_with_props<P: 'static + Send>(
188188
let _ = proxy.send_event(UserWindowEvent::Update);
189189
}
190190
"browser_open" => {
191+
println!("browser_open");
191192
let data = req.params.unwrap();
192193
log::trace!("Open browser: {:?}", data);
193194
if let Some(arr) = data.as_array() {

0 commit comments

Comments
 (0)