chore: clean up examples and fix link opening code
This commit is contained in:
parent
cc99fa8eb2
commit
6905bf98d7
|
@ -18,11 +18,6 @@ fn app(cx: Scope) -> Element {
|
|||
disabled: "{disabled}",
|
||||
"lower button"
|
||||
}
|
||||
|
||||
input {
|
||||
value: "false",
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ struct ListBreeds {
|
|||
}
|
||||
|
||||
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")
|
||||
.await
|
||||
.unwrap()
|
||||
|
@ -26,7 +26,7 @@ fn app(cx: Scope) -> Element {
|
|||
|
||||
let (breed, set_breed) = use_state(&cx, || None);
|
||||
|
||||
match fut.value() {
|
||||
match breeds.value() {
|
||||
Some(Ok(breeds)) => cx.render(rsx! {
|
||||
div {
|
||||
h1 {"Select a dog breed!"}
|
||||
|
|
|
@ -56,7 +56,6 @@ fn app(cx: Scope) -> Element {
|
|||
)
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ fn main() {
|
|||
dioxus::desktop::launch_with_props(app, (), |c| {
|
||||
c.with_file_drop_handler(|_w, e| {
|
||||
println!("{:?}", e);
|
||||
false
|
||||
true
|
||||
})
|
||||
});
|
||||
}
|
||||
|
|
|
@ -17,9 +17,9 @@ impl Label {
|
|||
fn new_list(num: usize) -> Vec<Self> {
|
||||
let mut rng = SmallRng::from_entropy();
|
||||
let mut labels = Vec::with_capacity(num);
|
||||
for _ in 0..num {
|
||||
for x in 0..num {
|
||||
labels.push(Label {
|
||||
key: 0,
|
||||
key: x,
|
||||
labels: [
|
||||
ADJECTIVES.choose(&mut rng).unwrap(),
|
||||
COLOURS.choose(&mut rng).unwrap(),
|
||||
|
|
|
@ -200,14 +200,35 @@ export class Interpreter {
|
|||
let target = event.target;
|
||||
if (target != null) {
|
||||
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
|
||||
while (realId == null && target.parentElement != null) {
|
||||
target = target.parentElement;
|
||||
realId = target.getAttribute(`data-dioxus-id`);
|
||||
}
|
||||
const shouldPreventDefault = target.getAttribute(
|
||||
|
||||
shouldPreventDefault = target.getAttribute(
|
||||
`dioxus-prevent-default`
|
||||
);
|
||||
|
||||
let contents = serialize_event(event);
|
||||
if (shouldPreventDefault === `on${event.type}`) {
|
||||
event.preventDefault();
|
||||
|
@ -215,25 +236,6 @@ export class Interpreter {
|
|||
if (event.type == "submit") {
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -188,6 +188,7 @@ pub fn launch_with_props<P: 'static + Send>(
|
|||
let _ = proxy.send_event(UserWindowEvent::Update);
|
||||
}
|
||||
"browser_open" => {
|
||||
println!("browser_open");
|
||||
let data = req.params.unwrap();
|
||||
log::trace!("Open browser: {:?}", data);
|
||||
if let Some(arr) = data.as_array() {
|
||||
|
|
Loading…
Reference in New Issue