mirror of
https://github.com/leptos-rs/leptos.git
synced 2025-12-27 07:34:35 -05:00
Remove unnecessary Option wrapping (#4035)
* Remove unnecessary Option wrapping. * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -300,7 +300,7 @@ fn inert_element_to_tokens(
|
||||
node: &Node<impl CustomNode>,
|
||||
escape_text: bool,
|
||||
global_class: Option<&TokenTree>,
|
||||
) -> Option<TokenStream> {
|
||||
) -> TokenStream {
|
||||
let mut html = InertElementBuilder::new(global_class);
|
||||
let mut nodes = VecDeque::from([Item::Node(node, escape_text)]);
|
||||
|
||||
@@ -396,9 +396,9 @@ fn inert_element_to_tokens(
|
||||
|
||||
html.finish();
|
||||
|
||||
Some(quote! {
|
||||
quote! {
|
||||
::leptos::tachys::html::InertElement::new(#html)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn element_children_to_tokens(
|
||||
@@ -597,7 +597,7 @@ fn node_to_tokens(
|
||||
let escape = el_name != "script"
|
||||
&& el_name != "style"
|
||||
&& el_name != "textarea";
|
||||
inert_element_to_tokens(node, escape, global_class)
|
||||
Some(inert_element_to_tokens(node, escape, global_class))
|
||||
} else {
|
||||
element_to_tokens(
|
||||
el_node,
|
||||
|
||||
@@ -144,16 +144,12 @@ impl RouterContext {
|
||||
resolve_path("", path, None)
|
||||
};
|
||||
|
||||
let mut url = match resolved_to.map(|to| BrowserUrl::parse(&to)) {
|
||||
Some(Ok(url)) => url,
|
||||
Some(Err(e)) => {
|
||||
let mut url = match BrowserUrl::parse(&resolved_to) {
|
||||
Ok(url) => url,
|
||||
Err(e) => {
|
||||
leptos::logging::error!("Error parsing URL: {e:?}");
|
||||
return;
|
||||
}
|
||||
None => {
|
||||
leptos::logging::error!("Error resolving relative URL.");
|
||||
return;
|
||||
}
|
||||
};
|
||||
let query_mutations =
|
||||
mem::take(&mut *self.query_mutations.write_value());
|
||||
@@ -203,7 +199,7 @@ impl RouterContext {
|
||||
&'a self,
|
||||
path: &'a str,
|
||||
from: Option<&'a str>,
|
||||
) -> Option<Cow<'a, str>> {
|
||||
) -> Cow<'a, str> {
|
||||
let base = self.base.as_deref().unwrap_or_default();
|
||||
resolve_path(base, path, from)
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ where
|
||||
fn inner(
|
||||
has_router: bool,
|
||||
method: Option<&'static str>,
|
||||
action: ArcMemo<Option<String>>,
|
||||
action: ArcMemo<String>,
|
||||
enctype: Option<String>,
|
||||
version: Option<RwSignal<usize>>,
|
||||
error: Option<RwSignal<Option<Box<dyn Error + Send + Sync>>>>,
|
||||
@@ -311,7 +311,7 @@ where
|
||||
let action = if has_router {
|
||||
use_resolved_path(move || action.to_href()())
|
||||
} else {
|
||||
ArcMemo::new(move |_| Some(action.to_href()()))
|
||||
ArcMemo::new(move |_| action.to_href()())
|
||||
};
|
||||
inner(
|
||||
has_router,
|
||||
|
||||
@@ -240,7 +240,7 @@ pub(crate) struct Matched(pub ArcMemo<String>);
|
||||
#[track_caller]
|
||||
pub(crate) fn use_resolved_path(
|
||||
path: impl Fn() -> String + Send + Sync + 'static,
|
||||
) -> ArcMemo<Option<String>> {
|
||||
) -> ArcMemo<String> {
|
||||
let router = use_context::<RouterContext>()
|
||||
.expect("called use_resolved_path outside a <Router>");
|
||||
// TODO make this work with flat routes too?
|
||||
@@ -248,14 +248,14 @@ pub(crate) fn use_resolved_path(
|
||||
ArcMemo::new(move |_| {
|
||||
let path = path();
|
||||
if path.starts_with('/') {
|
||||
Some(path)
|
||||
path
|
||||
} else {
|
||||
router
|
||||
.resolve_path(
|
||||
&path,
|
||||
matched.as_ref().map(|n| n.get()).as_deref(),
|
||||
)
|
||||
.map(|n| n.to_string())
|
||||
.to_string()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ where
|
||||
H: ToHref + Send + Sync + 'static,
|
||||
{
|
||||
fn inner(
|
||||
href: ArcMemo<Option<String>>,
|
||||
href: ArcMemo<String>,
|
||||
target: Option<Oco<'static, str>>,
|
||||
exact: bool,
|
||||
children: Children,
|
||||
@@ -114,23 +114,22 @@ where
|
||||
let is_active = {
|
||||
let href = href.clone();
|
||||
move || {
|
||||
href.read().as_deref().is_some_and(|to| {
|
||||
let path = to.split(['?', '#']).next().unwrap_or_default();
|
||||
current_url.with(|loc| {
|
||||
let loc = loc.path();
|
||||
if exact {
|
||||
loc == path
|
||||
} else {
|
||||
is_active_for(path, loc, strict_trailing_slash)
|
||||
}
|
||||
})
|
||||
let to = href.read();
|
||||
let path = to.split(['?', '#']).next().unwrap_or_default();
|
||||
current_url.with(|loc| {
|
||||
let loc = loc.path();
|
||||
if exact {
|
||||
loc == path
|
||||
} else {
|
||||
is_active_for(path, loc, strict_trailing_slash)
|
||||
}
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
view! {
|
||||
<a
|
||||
href=move || href.get().unwrap_or_default()
|
||||
href=move || href.get()
|
||||
target=target
|
||||
aria-current=move || if is_active() { Some("page") } else { None }
|
||||
data-noscroll=!scroll
|
||||
|
||||
@@ -4,9 +4,9 @@ pub fn resolve_path<'a>(
|
||||
base: &'a str,
|
||||
path: &'a str,
|
||||
from: Option<&'a str>,
|
||||
) -> Option<Cow<'a, str>> {
|
||||
) -> Cow<'a, str> {
|
||||
if has_scheme(path) {
|
||||
Some(path.into())
|
||||
path.into()
|
||||
} else {
|
||||
let base_path = normalize(base, false);
|
||||
let from_path = from.map(|from| normalize(from, false));
|
||||
@@ -25,7 +25,7 @@ pub fn resolve_path<'a>(
|
||||
let result_empty = result.is_empty();
|
||||
let prefix = if result_empty { "/".into() } else { result };
|
||||
|
||||
Some(prefix + normalize(path, result_empty))
|
||||
prefix + normalize(path, result_empty)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user