diff --git a/src/main.rs b/src/main.rs index 3584b85..ffd3105 100644 --- a/src/main.rs +++ b/src/main.rs @@ -140,28 +140,30 @@ async fn kernel(excess: &str) -> Template { // Handling search request. -#[post("/search", data="")] -fn search(input: &str) -> Either { - //Check input length - if input.len() > "search=".len() { - // Trim 'search=' from the request data - let input = &input[7..].to_lowercase(); +// Using Option<&str> to match '/search' query without input params. +// https://github.com/rwf2/Rocket/issues/608 +#[get("/search?")] +fn search(input: Option<&str>) -> Either { + // Unwrap Option and forward to Search page if no parameters + let input = match input { + Some(value) => value, + None => return Either::Left(Template::render("search", context! { route: "search", })), + }; - // Check for valid chars - if input.chars().all(|x| (x >= 'a' && x <= 'f') || (x >= '0' && x <= '9')) == true { + // Check for valid chars + if input.chars().all(|x| (x >= 'a' && x <= 'f') || (x >= '0' && x <= '9')) == true { - // Block number - if input.chars().all(char::is_numeric) == true { - return Either::Right(Redirect::to(uri!(block_details_by_height(input)))); + // Block number + if input.chars().all(char::is_numeric) == true { + return Either::Right(Redirect::to(uri!(block_details_by_height(input)))); - // Block hash - } else if input.len() == 64 { - return Either::Right(Redirect::to(uri!(block_header_by_hash(input)))); + // Block hash + } else if input.len() == 64 { + return Either::Right(Redirect::to(uri!(block_header_by_hash(input)))); - // Kernel - } else if input.len() == 66 { - return Either::Right(Redirect::to(uri!(kernel(input)))); - } + // Kernel + } else if input.len() == 66 { + return Either::Right(Redirect::to(uri!(kernel(input)))); } } @@ -255,9 +257,9 @@ fn sync_status(dashboard: &State>>) -> String { if data.sync == "no_sync" { "Synced".to_string() } else { - format!("Syncing ({}) + format!("Syncing - Syncing...", data.sync) + Syncing...") } } diff --git a/templates/base.html.tera b/templates/base.html.tera index 352d862..4b3bb6a 100644 --- a/templates/base.html.tera +++ b/templates/base.html.tera @@ -61,8 +61,8 @@ - - + + @@ -211,8 +211,11 @@ - - v.0.1.4 + + v.0.1.4 + + + search diff --git a/templates/error.html.tera b/templates/error.html.tera index 88b82f8..5bda901 100644 --- a/templates/error.html.tera +++ b/templates/error.html.tera @@ -7,7 +7,10 @@ No results found. - Explorer supports requests by block number, block hash or kernel. + Supported search inputs: + block number + block hash + kernel diff --git a/templates/search.html.tera b/templates/search.html.tera new file mode 100644 index 0000000..d702ed3 --- /dev/null +++ b/templates/search.html.tera @@ -0,0 +1,32 @@ +{% extends "base" %} + +{% block content %} + + + + + + + + + + + + + + + + + Supported search inputs: + block number + block hash + kernel + + + + + + + +{% endblock %} +
+ + + + + + + + + + + + + + + Supported search inputs: + block number + block hash + kernel + + + + + +