rate_app/cases/
dashboard.rs

1use super::state::{SceneState, SCENE};
2use anyhow::Error;
3use rate_ui::shared_object::{DataChanged, SharedObject};
4use rate_ui::widget::{Context, NotificationHandler, Widget, WidgetRuntime};
5use yew::{html, Html};
6
7pub type Dashboard = WidgetRuntime<DashboardWidget>;
8
9pub struct DashboardWidget {
10    scene: SharedObject<SceneState>,
11}
12
13impl Default for DashboardWidget {
14    fn default() -> Self {
15        Self {
16            scene: SCENE.with(SharedObject::clone),
17        }
18    }
19}
20
21impl Widget for DashboardWidget {
22    type Event = ();
23    type Tag = ();
24    type Properties = ();
25    type Meta = ();
26
27    fn init(&mut self, ctx: &mut Context<Self>) {
28        self.scene.subscribe(ctx);
29    }
30
31    fn view(&self, _ctx: &Context<Self>) -> Html {
32        let state = self.scene.read();
33        if let Some(layout) = state.get_layout_tab() {
34            html! {
35                <super::LayoutViewer layout_tab=layout.clone() />
36            }
37        } else {
38            html! {
39                <p>{ "Loading" }</p>
40            }
41        }
42    }
43}
44
45impl NotificationHandler<DataChanged<SceneState>> for DashboardWidget {
46    fn handle(
47        &mut self,
48        _event: DataChanged<SceneState>,
49        ctx: &mut Context<Self>,
50    ) -> Result<(), Error> {
51        ctx.redraw();
52        Ok(())
53    }
54}