Merge branch 'master' into liveview-history-default

This commit is contained in:
ealmloff authored and GitHub committed 2024-01-08 13:11:55 -06:00
commit 08a679147f
249 files changed
+12339 -4555

No files matched your search

+14
View File
@@ -1,5 +1,19 @@
use crate::prelude::{ExternalNavigationFailure, IntoRoutable, RouterContext};
/// Acquire the navigator without subscribing to updates.
///
/// Can be called anywhere in the application provided a Router has been initialized.
///
/// ## Panics
///
/// Panics if there is no router present.
pub fn navigator() -> Navigator {
Navigator(
dioxus::core::prelude::consume_context::<RouterContext>()
.expect("A router must be present to use navigator"),
)
}
/// A view into the navigation state of a router.
#[derive(Clone)]
pub struct Navigator(pub(crate) RouterContext);
+6 -1
View File
@@ -2,7 +2,7 @@ use dioxus::prelude::ScopeState;
use crate::{prelude::RouterContext, utils::use_router_internal::use_router_internal};
#[deprecated = "prefer the use_navigator or use_route functions"]
#[deprecated = "prefer the `router()` function or `use_route` functions"]
#[must_use]
/// A hook that provides access to information about the router.
pub fn use_router(cx: &ScopeState) -> &RouterContext {
@@ -10,3 +10,8 @@ pub fn use_router(cx: &ScopeState) -> &RouterContext {
.as_ref()
.expect("use_route must have access to a router")
}
/// Aquire the router without subscribing to updates.
pub fn router() -> RouterContext {
dioxus::core::prelude::consume_context().unwrap()
}
+2
View File
@@ -53,6 +53,8 @@ pub mod hooks {
pub use use_navigator::*;
}
pub use hooks::router;
/// A collection of useful items most applications might need.
pub mod prelude {
pub use crate::components::*;
+36 -1
View File
@@ -24,7 +24,7 @@ impl<E: Display> Display for RouteParseError<E> {
}
}
/// Something that can be created from a query string.
/// Something that can be created from an entire query string.
///
/// This trait needs to be implemented if you want to turn a query string into a struct.
///
@@ -40,6 +40,41 @@ impl<T: for<'a> From<&'a str>> FromQuery for T {
}
}
/// Something that can be created from a query argument.
///
/// This trait must be implemented for every type used within a query string in the router macro.
pub trait FromQueryArgument: Default {
/// The error that can occur when parsing a query argument.
type Err;
/// Create an instance of `Self` from a query string.
fn from_query_argument(argument: &str) -> Result<Self, Self::Err>;
}
impl<T: Default + FromStr> FromQueryArgument for T
where
<T as FromStr>::Err: Display,
{
type Err = <T as FromStr>::Err;
fn from_query_argument(argument: &str) -> Result<Self, Self::Err> {
let result = match urlencoding::decode(argument) {
Ok(argument) => T::from_str(&argument),
Err(err) => {
tracing::error!("Failed to decode url encoding: {}", err);
T::from_str(argument)
}
};
match result {
Ok(result) => Ok(result),
Err(err) => {
tracing::error!("Failed to parse query argument: {}", err);
Err(err)
}
}
}
}
/// Something that can be created from a route segment.
pub trait FromRouteSegment: Sized {
/// The error that can occur when parsing a route segment.