aper_yew/
view.rs

1use aper_stateroom::StateProgram;
2use chrono::{DateTime, Duration, Utc};
3use yew::{Callback, Html};
4
5pub struct StateProgramViewContext<P: StateProgram> {
6    pub callback: Callback<P::T>,
7    pub redraw: Callback<()>,
8    pub client_id: u32,
9    pub offset: Duration,
10}
11
12impl<P: StateProgram> StateProgramViewContext<P> {
13    pub fn timestamp(&self) -> DateTime<Utc> {
14        Utc::now().checked_add_signed(self.offset).unwrap()
15    }
16}
17
18pub trait StateProgramViewComponent: 'static {
19    type Program: StateProgram;
20
21    fn view(state: &Self::Program, context: StateProgramViewContext<Self::Program>) -> Html;
22}