浏览代码

chore: clean up examples and fix link opening code

Jonathan Kelley 3 年之前
父节点
当前提交
6905bf98d7

+ 0 - 5
examples/disabled.rs

@@ -18,11 +18,6 @@ fn app(cx: Scope) -> Element {
                 disabled: "{disabled}",
                 disabled: "{disabled}",
                 "lower button"
                 "lower button"
             }
             }
-
-            input {
-                value: "false",
-            }
-
         }
         }
     })
     })
 }
 }

+ 2 - 2
examples/dog_app.rs

@@ -16,7 +16,7 @@ struct ListBreeds {
 }
 }
 
 
 fn app(cx: Scope) -> Element {
 fn app(cx: Scope) -> Element {
-    let fut = use_future(&cx, || async move {
+    let breeds = use_future(&cx, || async move {
         reqwest::get("https://dog.ceo/api/breeds/list/all")
         reqwest::get("https://dog.ceo/api/breeds/list/all")
             .await
             .await
             .unwrap()
             .unwrap()
@@ -26,7 +26,7 @@ fn app(cx: Scope) -> Element {
 
 
     let (breed, set_breed) = use_state(&cx, || None);
     let (breed, set_breed) = use_state(&cx, || None);
 
 
-    match fut.value() {
+    match breeds.value() {
         Some(Ok(breeds)) => cx.render(rsx! {
         Some(Ok(breeds)) => cx.render(rsx! {
             div {
             div {
                 h1 {"Select a dog breed!"}
                 h1 {"Select a dog breed!"}

+ 0 - 1
examples/file_explorer.rs

@@ -56,7 +56,6 @@ fn app(cx: Scope) -> Element {
                 )
                 )
             })
             })
         }
         }
-
     })
     })
 }
 }
 
 

+ 1 - 1
examples/filedragdrop.rs

@@ -4,7 +4,7 @@ fn main() {
     dioxus::desktop::launch_with_props(app, (), |c| {
     dioxus::desktop::launch_with_props(app, (), |c| {
         c.with_file_drop_handler(|_w, e| {
         c.with_file_drop_handler(|_w, e| {
             println!("{:?}", e);
             println!("{:?}", e);
-            false
+            true
         })
         })
     });
     });
 }
 }

+ 2 - 2
examples/framework_benchmark.rs

@@ -17,9 +17,9 @@ impl Label {
     fn new_list(num: usize) -> Vec<Self> {
     fn new_list(num: usize) -> Vec<Self> {
         let mut rng = SmallRng::from_entropy();
         let mut rng = SmallRng::from_entropy();
         let mut labels = Vec::with_capacity(num);
         let mut labels = Vec::with_capacity(num);
-        for _ in 0..num {
+        for x in 0..num {
             labels.push(Label {
             labels.push(Label {
-                key: 0,
+                key: x,
                 labels: [
                 labels: [
                     ADJECTIVES.choose(&mut rng).unwrap(),
                     ADJECTIVES.choose(&mut rng).unwrap(),
                     COLOURS.choose(&mut rng).unwrap(),
                     COLOURS.choose(&mut rng).unwrap(),

+ 22 - 20
packages/desktop/src/interpreter.js

@@ -200,14 +200,35 @@ export class Interpreter {
           let target = event.target;
           let target = event.target;
           if (target != null) {
           if (target != null) {
             let realId = target.getAttribute(`data-dioxus-id`);
             let realId = target.getAttribute(`data-dioxus-id`);
+            let shouldPreventDefault = target.getAttribute(
+              `dioxus-prevent-default`
+            );
+
+            if (event.type == "click") {
+              event.preventDefault();
+              if (shouldPreventDefault !== `onclick`) {
+                console.log("click", event);
+                console.log("clickeded", event.target);
+                console.log("clickeded", event.target.tagName);
+                if (target.tagName == "A") {
+                  const href = target.getAttribute("href");
+                  if (href !== "" && href !== null && href !== undefined) {
+                    window.rpc.call("browser_open", { href });
+                  }
+                }
+              }
+            }
+
             // walk the tree to find the real element
             // walk the tree to find the real element
             while (realId == null && target.parentElement != null) {
             while (realId == null && target.parentElement != null) {
               target = target.parentElement;
               target = target.parentElement;
               realId = target.getAttribute(`data-dioxus-id`);
               realId = target.getAttribute(`data-dioxus-id`);
             }
             }
-            const shouldPreventDefault = target.getAttribute(
+
+            shouldPreventDefault = target.getAttribute(
               `dioxus-prevent-default`
               `dioxus-prevent-default`
             );
             );
+
             let contents = serialize_event(event);
             let contents = serialize_event(event);
             if (shouldPreventDefault === `on${event.type}`) {
             if (shouldPreventDefault === `on${event.type}`) {
               event.preventDefault();
               event.preventDefault();
@@ -215,25 +236,6 @@ export class Interpreter {
             if (event.type == "submit") {
             if (event.type == "submit") {
               event.preventDefault();
               event.preventDefault();
             }
             }
-            if (event.type == "click") {
-              event.preventDefault();
-              if (shouldPreventDefault !== `onclick`) {
-                if (target.tagName == "A") {
-                  const href = target.getAttribute("href");
-                  if (
-                    href !== "" &&
-                    href !== null &&
-                    href !== undefined &&
-                    realId != null
-                  ) {
-                    window.rpc.call("browser_open", {
-                      mounted_dom_id: parseInt(realId),
-                      href,
-                    });
-                  }
-                }
-              }
-            }
             if (realId == null) {
             if (realId == null) {
               return;
               return;
             }
             }

+ 1 - 0
packages/desktop/src/lib.rs

@@ -188,6 +188,7 @@ pub fn launch_with_props<P: 'static + Send>(
                                 let _ = proxy.send_event(UserWindowEvent::Update);
                                 let _ = proxy.send_event(UserWindowEvent::Update);
                             }
                             }
                             "browser_open" => {
                             "browser_open" => {
+                                println!("browser_open");
                                 let data = req.params.unwrap();
                                 let data = req.params.unwrap();
                                 log::trace!("Open browser: {:?}", data);
                                 log::trace!("Open browser: {:?}", data);
                                 if let Some(arr) = data.as_array() {
                                 if let Some(arr) = data.as_array() {