Closed beckend closed 1 year ago
here is portal.rs
use crate::globals::StatePortalMain;
use leptos::*;
use std::{cell::RefCell, fmt::Debug, sync::Arc, time::Duration};
turf::style_sheet!("src/components/portal.scss");
#[derive(Clone)]
struct StateLocal {
pub children: Arc<RefCell<Option<ChildrenFnMut>>>,
}
#[component]
pub fn ComponentModal() -> impl IntoView {
let (state_local, state_local_set) = create_signal(StateLocal {
children: Arc::new(RefCell::new(None::<ChildrenFnMut>)),
});
let state_signal = expect_context::<RwSignal<StatePortalMain>>();
create_effect(move |_| {
let state = state_signal.get();
let state_component = state.component.get();
let component_new_read = state_component.borrow();
let component_new_exists = component_new_read.is_some();
drop(component_new_read);
// always use the new one, removing the old
if component_new_exists {
state.is_rendered.update(|x| {
*x = true;
state_local_set.update(|value| {
*value.children.borrow_mut() = state_component.take();
});
});
}
});
let fn_get_should_show = move || state_signal.get().is_rendered;
view! {
<style>{STYLE_SHEET}</style>
{move || {
view! {
<AnimatedShow
when=fn_get_should_show()
show_class="this--modal--main this--modal--main--opening"
hide_class="this--modal--main this--modal--main--closing"
hide_delay=Duration::from_millis(1000)
>
{move || {
let cell = state_local.get();
let mut lock = cell.children.borrow_mut();
if let Some(children) = lock.as_mut() {
return Some(
view! {
<aside class=ClassName::BACKGROUND>
<div class=ClassName::CONTENT>{children()}</div>
</aside>
},
);
}
None::<HtmlElement<leptos::html::Aside>>
}}
</AnimatedShow>
}
}}
}
}
#[derive(Debug)]
pub struct APIModal {}
impl APIModal {
pub fn get_context() -> RwSignal<StatePortalMain> {
expect_context::<RwSignal<StatePortalMain>>()
}
pub fn open(signal: RwSignal<StatePortalMain>, frag: Fragment) {
let state = signal.get();
state.component.update(move |x| {
x.replace_with(move |_| Some(Box::new(move || frag.to_owned())));
});
}
pub fn close(signal: RwSignal<StatePortalMain>) {
signal.get().is_rendered.update(|x| *x = false);
}
}
I am not able to reproduce this. The provided code can't compile because it depends on declarations from your project. I have tried to reproduce a similar use case but have not encountered any problems.
To help me understand the problem can you please create a minimal reproducible example? In addition, could you please check what class names turf generates? You can make turf print the generated class names by adding the following code to your projects Cargo.toml
:
[package.metadata.turf]
debug = true
You will need to trigger recompilation though, as the syle_sheet!
macro only gets executed during compilation and not when running a cached build.
Ok thanks. I have paused my rust project for now.
The ids differs and so the CSS never applies.
cargo.toml