mirror of
https://github.com/adoyle0/thaw.git
synced 2025-01-23 06:19:22 -05:00
fix: ToasterInjection supports Copy
This commit is contained in:
parent
c9c8e34143
commit
a242b307af
3 changed files with 18 additions and 18 deletions
|
@ -1,11 +1,10 @@
|
||||||
# Menu
|
# Menu
|
||||||
|
|
||||||
```rust demo
|
```rust demo
|
||||||
|
let toaster = ToasterInjection::expect_context();
|
||||||
|
|
||||||
|
let on_select = move |key: String| {
|
||||||
let on_select = |key: String| {
|
|
||||||
leptos::logging::warn!("{}", key);
|
leptos::logging::warn!("{}", key);
|
||||||
let toaster = ToasterInjection::expect_context();
|
|
||||||
toaster.dispatch_toast(view! {
|
toaster.dispatch_toast(view! {
|
||||||
<Toast>
|
<Toast>
|
||||||
<ToastBody>
|
<ToastBody>
|
||||||
|
|
|
@ -30,9 +30,9 @@ view! {
|
||||||
### Toast Positions
|
### Toast Positions
|
||||||
|
|
||||||
```rust demo
|
```rust demo
|
||||||
fn dispatch_toast(position: ToastPosition) {
|
let toaster = ToasterInjection::expect_context();
|
||||||
let toaster = ToasterInjection::expect_context();
|
|
||||||
|
|
||||||
|
fn dispatch_toast(toaster: ToasterInjection, position: ToastPosition) {
|
||||||
toaster.dispatch_toast(view! {
|
toaster.dispatch_toast(view! {
|
||||||
<Toast>
|
<Toast>
|
||||||
<ToastTitle>"Email sent"</ToastTitle>
|
<ToastTitle>"Email sent"</ToastTitle>
|
||||||
|
@ -53,12 +53,12 @@ fn dispatch_toast(position: ToastPosition) {
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
<Space>
|
<Space>
|
||||||
<Button on_click=move |_| dispatch_toast(ToastPosition::Bottom)>"Bottom"</Button>
|
<Button on_click=move |_| dispatch_toast(toaster, ToastPosition::Bottom)>"Bottom"</Button>
|
||||||
<Button on_click=move |_| dispatch_toast(ToastPosition::BottomStart)>"BottomStart"</Button>
|
<Button on_click=move |_| dispatch_toast(toaster, ToastPosition::BottomStart)>"BottomStart"</Button>
|
||||||
<Button on_click=move |_| dispatch_toast(ToastPosition::BottomEnd)>"BottomEnd"</Button>
|
<Button on_click=move |_| dispatch_toast(toaster, ToastPosition::BottomEnd)>"BottomEnd"</Button>
|
||||||
<Button on_click=move |_| dispatch_toast(ToastPosition::Top)>"Top"</Button>
|
<Button on_click=move |_| dispatch_toast(toaster, ToastPosition::Top)>"Top"</Button>
|
||||||
<Button on_click=move |_| dispatch_toast(ToastPosition::TopStart)>"Topstart"</Button>
|
<Button on_click=move |_| dispatch_toast(toaster, ToastPosition::TopStart)>"Topstart"</Button>
|
||||||
<Button on_click=move |_| dispatch_toast(ToastPosition::TopEnd)>"TopEnd"</Button>
|
<Button on_click=move |_| dispatch_toast(toaster, ToastPosition::TopEnd)>"TopEnd"</Button>
|
||||||
</Space>
|
</Space>
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -16,10 +16,10 @@ use std::sync::mpsc::{channel, Receiver, Sender, TryIter};
|
||||||
use tachys::view::any_view::AnyView;
|
use tachys::view::any_view::AnyView;
|
||||||
use wasm_bindgen::UnwrapThrowExt;
|
use wasm_bindgen::UnwrapThrowExt;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct ToasterInjection {
|
pub struct ToasterInjection {
|
||||||
sender: Sender<(AnyView<Dom>, ToastOptions)>,
|
sender: StoredValue<Sender<(AnyView<Dom>, ToastOptions)>>,
|
||||||
trigger: ArcTrigger,
|
trigger: StoredValue<ArcTrigger>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToasterInjection {
|
impl ToasterInjection {
|
||||||
|
@ -33,16 +33,17 @@ impl ToasterInjection {
|
||||||
|
|
||||||
(
|
(
|
||||||
Self {
|
Self {
|
||||||
sender,
|
sender: StoredValue::new(sender),
|
||||||
trigger: trigger.clone(),
|
trigger: StoredValue::new(trigger.clone()),
|
||||||
},
|
},
|
||||||
ToasterReceiver::new(receiver, trigger),
|
ToasterReceiver::new(receiver, trigger),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dispatch_toast(&self, any_view: AnyView<Dom>, options: ToastOptions) {
|
pub fn dispatch_toast(&self, any_view: AnyView<Dom>, options: ToastOptions) {
|
||||||
self.sender.send((any_view, options)).unwrap_throw();
|
self.sender
|
||||||
self.trigger.trigger();
|
.with_value(|sender| sender.send((any_view, options)).unwrap_throw());
|
||||||
|
self.trigger.with_value(|trigger| trigger.trigger());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue