update tests

This commit is contained in:
Evan Almloff committed 2023-05-31 13:57:33 -05:00
1 parent 58b74c1155
commit 35befa1784
12 files changed
+334 -236

No files matched your search

+3 -11
View File
@@ -152,18 +152,10 @@ pub fn GenericLink<'a, R: Routable + Clone>(cx: Scope<'a, GenericLinkProps<'a, R
};
let current_route = router.current();
let href = current_route.to_string();
let current_url = current_route.to_string();
let href = target.to_string();
let ac = active_class
.and_then(|active_class| match target {
NavigationTarget::Internal(target) => {
if href == target.to_string() {
Some(format!(" {active_class}"))
} else {
None
}
}
_ => None,
})
.and_then(|active_class| (href == current_url).then(|| format!(" {active_class}")))
.unwrap_or_default();
let id = id.unwrap_or_default();
-9
View File
@@ -38,8 +38,6 @@ pub struct GenericRouterProps<R: Routable>
where
<R as FromStr>::Err: std::fmt::Display,
{
#[props(into)]
initial_url: Option<String>,
#[props(default, into)]
config: RouterCfg<R>,
}
@@ -71,13 +69,6 @@ where
cx.props.config.config.take().unwrap_or_default(),
cx.schedule_update_any(),
);
if let Some(initial) = cx.props.initial_url.as_ref() {
router.replace(
initial
.parse()
.unwrap_or_else(|_| panic!("failed to parse initial url")),
);
}
router
});
+11
View File
@@ -51,6 +51,17 @@ pub mod prelude {
pub use crate::routable::*;
pub use crate::router_cfg::RouterConfiguration;
pub use dioxus_router_macro::Routable;
#[doc(hidden)]
/// A component with props used in the macro
pub trait HasProps {
/// The props type of the component.
type Props;
}
impl<P> HasProps for dioxus::prelude::Component<P> {
type Props = P;
}
}
mod utils {
+16
View File
@@ -29,6 +29,22 @@ pub enum NavigationTarget<R: Routable> {
External(String),
}
impl<R: Routable> From<&str> for NavigationTarget<R>
where
<R as FromStr>::Err: Display,
{
fn from(value: &str) -> Self {
Self::from_str(value).unwrap_or_else(|err| match err {
NavigationTargetParseError::InvalidUrl(e) => {
panic!("Failed to parse `{}` as a URL: {}", value, e)
}
NavigationTargetParseError::InvalidInternalURL(e) => {
panic!("Failed to parse `{}` as a `Routable`: {}", value, e)
}
})
}
}
impl<R: Routable> From<R> for NavigationTarget<R> {
fn from(value: R) -> Self {
Self::Internal(value)