From 4d986782d87592f9983af6fcf2997593c315c72f Mon Sep 17 00:00:00 2001 From: Spencer Christiansen Date: Thu, 14 Mar 2024 10:47:18 -0600 Subject: [PATCH] Add note about special bases to try Fix clippy issues --- src/bases.rs | 2 +- src/components/home_inputs.rs | 4 ++-- src/lib.rs | 2 -- src/pages/home.rs | 21 +++++++++++++++++---- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/bases.rs b/src/bases.rs index 33d399e..729b551 100644 --- a/src/bases.rs +++ b/src/bases.rs @@ -8,7 +8,7 @@ pub fn rounded_string(num: BigDecimal, hard_limit: Option) -> String let str = num .with_precision_round(hl, bigdecimal::RoundingMode::Down) .to_string(); - if str.split("E").count() > 1 { + if str.split('E').count() > 1 { return str; } else { return format!("{}…", str); // ellide diff --git a/src/components/home_inputs.rs b/src/components/home_inputs.rs index ffa706e..5c1e1ad 100644 --- a/src/components/home_inputs.rs +++ b/src/components/home_inputs.rs @@ -7,7 +7,7 @@ use crate::components::value_in_base::value_in_base; #[component] pub fn HomeInputs( - string_value: Memo>, + base10_representation: Memo>, output_representation: Memo>, #[prop(into)] input_string: Signal, #[prop(into)] set_input_string: WriteSignal, @@ -23,7 +23,7 @@ pub fn HomeInputs( thead().child( tr().child(th().child("Value in Base-10:")) .child(th().child(value_in_base( - string_value, + base10_representation, (|| BigDecimal::from(10)).into(), ))), ), diff --git a/src/lib.rs b/src/lib.rs index d3e0946..ffc71b6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,6 @@ use leptos::*; use leptos_meta::*; -use leptos_router::*; // Modules mod bases; @@ -11,7 +10,6 @@ mod pages; // Top-Level pages use crate::pages::home::Home; -use crate::pages::not_found::NotFound; /// An app router which renders the homepage and handles 404's #[component] diff --git a/src/pages/home.rs b/src/pages/home.rs index c73375d..15137fd 100644 --- a/src/pages/home.rs +++ b/src/pages/home.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use bigdecimal::BigDecimal; -use leptos::*; +use leptos::{html::*, *}; use crate::{ bases::{val_from_base, val_to_base}, @@ -11,13 +11,13 @@ use crate::{ /// Default Home Page #[component] pub fn Home() -> impl IntoView { - let (input_string, set_input_string) = create_signal("23982982383829823983".to_string()); + let (input_string, set_input_string) = create_signal("123.45".to_string()); let (input_base, set_input_base) = create_signal(BigDecimal::from_str("10.3").unwrap()); let (output_base, set_output_base) = create_signal(BigDecimal::from_str("10.3").unwrap()); let result_value = create_memo(move |_| val_from_base(&input_string(), &input_base())); - let string_value = + let base10_representation = create_memo(move |_| result_value().and_then(|v| val_to_base(&v, &BigDecimal::from(10)))); let output_representation = create_memo(move |_| { result_value() @@ -25,6 +25,17 @@ pub fn Home() -> impl IntoView { .and_then(|v| val_to_base(&v, &output_base())) }); + let also_try = sub() + .child("Also try bases: ") + .child(code().child("pi")) + .child(", ") + .child(code().child("e")) + .child(", ") + .child(code().child("sqrt2")) + .child(", ") + .child(code().child("phi")) + .child("."); + view! { impl IntoView {

"ChangeBase"

impl IntoView { set_output_base=set_output_base /> + {also_try} +