use std::rc::Rc; use yew::prelude::*; use yewdux::prelude::*; use crate::{components, stores}; pub enum Msg { UpdateNotifications(Rc), Remove(usize), } pub struct NotificationListing { notifications: Rc, notifications_dispatch: Dispatch, } impl Component for NotificationListing { type Message = Msg; type Properties = (); fn create(ctx: &Context) -> Self { let notifications_dispatch = Dispatch::subscribe(ctx.link().callback(Msg::UpdateNotifications)); Self { notifications: notifications_dispatch.get(), notifications_dispatch, } } fn update(&mut self, _ctx: &Context, msg: Self::Message) -> bool { match msg { Msg::UpdateNotifications(x) => { self.notifications = x; true } Msg::Remove(i) => { self.notifications_dispatch .reduce_mut(|notifs| notifs.notifications.remove(&i)); true } } } fn view(&self, ctx: &Context) -> Html { let remove = Rc::new(ctx.link().callback(Msg::Remove)); html! { { for self.notifications.notifications.iter().rev().map(|(i, _)| html! { }) } } } }