fix: tests

This commit is contained in:
Jonathan Kelley committed 2022-01-05 17:30:12 -05:00
1 parent e2a6454527
commit bd341f5571
17 files changed
+305 -300

No files matched your search

+2 -2
View File
@@ -89,8 +89,8 @@ fn app(cx: Scope) -> Element {
#[derive(Props)]
struct ActionButtonProps<'a> {
name: &'static str,
id: &'static str,
name: &'a str,
id: &'a str,
onclick: &'a dyn Fn(),
}
+1 -1
View File
@@ -133,7 +133,7 @@ fn app(cx: Scope) -> Element {
r#type: "{field}",
value: "{value}",
// checked: "false",
oninput: move |evt: Arc<FormEvent>| {
oninput: move |evt: FormEvent| {
println!("{:?}", evt);
},
}
+1 -1
View File
@@ -35,5 +35,5 @@ fn main() {
let app: Component = |cx| cx.render(rsx!(div { "some app" }));
dioxus_desktop::launch_core(app, (), |c| c.with_edits(edits));
dioxus_desktop::launch_with_props(app, (), |c| c.with_edits(edits));
}
+3 -3
View File
@@ -116,8 +116,8 @@ fn app(cx: Scope) -> Element {
#[derive(Props)]
struct CalculatorKeyProps<'a> {
name: &'static str,
onclick: &'a dyn Fn(Arc<MouseEvent>),
name: &'a str,
onclick: &'a dyn Fn(MouseEvent),
children: Element<'a>,
}
@@ -211,7 +211,7 @@ impl Calculator {
self.cur_val = self.display_value.parse::<f64>().unwrap();
self.waiting_for_operand = true;
}
fn handle_keydown(&mut self, evt: Arc<KeyboardEvent>) {
fn handle_keydown(&mut self, evt: KeyboardEvent) {
match evt.key_code {
KeyCode::Backspace => self.backspace(),
KeyCode::Num0 => self.input_digit(0),
+40 -51
View File
@@ -1,64 +1,53 @@
#![allow(non_snake_case)]
use dioxus::prelude::*;
use dioxus_router::{use_router, Link};
use dioxus::router::{Link, Route, Router};
#[derive(PartialEq, Debug, Clone)]
pub enum Route {
// #[at("/")]
Home,
// #[at("/:id")]
AllUsers { page: u32 },
// #[at("/:id")]
User { id: u32 },
// #[at("/:id")]
BlogList { page: u32 },
// #[at("/:id")]
BlogPost { post_id: u32 },
// #[at("/404")]
// #[not_found]
NotFound,
fn main() {
dioxus::desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let route = use_router(&cx, Route::parse);
cx.render(rsx! {
nav {
Link { to: Route::Home, "Go home!" }
Link { to: Route::AllUsers { page: 0 }, "List all users" }
Link { to: Route::BlogList { page: 0 }, "Blog posts" }
Router {
ul {
Link { to: "/", li { "Go home!" } }
Link { to: "users", li { "List all users" } }
Link { to: "blog", li { "Blog posts" } }
}
Route { to: "/", "Home" }
Route { to: "users",
Route { to: "/", "User list" }
Route { to: ":name", BlogPost {} }
}
Route { to: "blog"
Route { to: "/", "Blog list" }
Route { to: ":post", BlogPost {} }
}
Route { to: "", "Err 404 Route Not Found" }
}
match route {
Route::Home => rsx!("Home"),
Route::AllUsers { page } => rsx!("All users - page {page}"),
Route::User { id } => rsx!("User - id: {id}"),
Route::BlogList { page } => rsx!("Blog posts - page {page}"),
Route::BlogPost { post_id } => rsx!("Blog post - post {post_id}"),
Route::NotFound => rsx!("Not found"),
}
footer {}
})
}
impl Route {
// Generate the appropriate route from the "tail" end of the URL
fn parse(url: &str) -> Self {
use Route::*;
match url {
"/" => Home,
"/users" => AllUsers { page: 1 },
"/users/:page" => AllUsers { page: 1 },
"/users/:page/:id" => User { id: 1 },
"/blog" => BlogList { page: 1 },
"/blog/:page" => BlogList { page: 1 },
"/blog/:page/:id" => BlogPost { post_id: 1 },
_ => NotFound,
fn BlogPost(cx: Scope) -> Element {
let post = dioxus::router::use_route(&cx).last_segment()?;
cx.render(rsx! {
div {
h1 { "Reading blog post: {post}" }
p { "example blog post" }
}
}
})
}
fn main() {}
fn User(cx: Scope) -> Element {
let post = dioxus::router::use_route(&cx).last_segment()?;
let bold = dioxus::router::use_route(&cx).param::<bool>("bold");
cx.render(rsx! {
div {
h1 { "Reading blog post: {post}" }
p { "example blog post" }
}
})
}