Recipe edit, we can now delete groups, steps and ingredients
This commit is contained in:
parent
d4962c98ff
commit
5ce3391466
11 changed files with 183 additions and 68 deletions
51
frontend/src/on_click.rs
Normal file
51
frontend/src/on_click.rs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
use futures::channel::mpsc;
|
||||
use futures::stream::Stream;
|
||||
use gloo::{console::log, events::EventListener, net::http::Request, utils::document};
|
||||
use std::{
|
||||
future::Future,
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
use wasm_bindgen::prelude::*;
|
||||
use web_sys::EventTarget;
|
||||
|
||||
// From: https://docs.rs/gloo-events/latest/gloo_events/struct.EventListener.html
|
||||
|
||||
pub struct OnClick {
|
||||
receiver: mpsc::UnboundedReceiver<()>,
|
||||
// Automatically removed from the DOM on drop.
|
||||
listener: EventListener,
|
||||
}
|
||||
|
||||
impl OnClick {
|
||||
pub fn new(target: &EventTarget) -> Self {
|
||||
let (sender, receiver) = mpsc::unbounded();
|
||||
|
||||
// Attach an event listener.
|
||||
let listener = EventListener::new(target, "click", move |_event| {
|
||||
sender.unbounded_send(()).unwrap_throw();
|
||||
});
|
||||
|
||||
Self { receiver, listener }
|
||||
}
|
||||
}
|
||||
|
||||
// Multiple clicks.
|
||||
impl Stream for OnClick {
|
||||
type Item = ();
|
||||
|
||||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
|
||||
Pin::new(&mut self.receiver).poll_next(cx)
|
||||
}
|
||||
}
|
||||
|
||||
// Just one click.
|
||||
impl Future for OnClick {
|
||||
type Output = ();
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
Pin::new(&mut self.receiver)
|
||||
.poll_next(cx)
|
||||
.map(Option::unwrap)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue