diff --git a/src/main.rs b/src/main.rs index ba564ad..ee444fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -129,6 +129,10 @@ async fn drinks(Path(id): Path) -> impl IntoResponse { } async fn shift_report(State(state): State, Path(id): Path) -> impl IntoResponse { + // TODO: Massive rework of how this works + // was experimenting with traits, but most of that + // didn't lead to what I was aiming for + let mut conn = state.connection.get().await.unwrap(); let shift: Shift = shifts::table.find(id).first(&mut conn).await.unwrap(); let drinks: Vec = Drink::belonging_to(&shift).load(&mut conn).await.unwrap(); diff --git a/src/sse_handler.rs b/src/sse_handler.rs index 8aee8d3..e6dd96c 100644 --- a/src/sse_handler.rs +++ b/src/sse_handler.rs @@ -3,6 +3,17 @@ pub enum SseMessage { RefreshAda, } +// I think for the ada_sender, a watch would be ideal if I want to always use full renders of the +// watchlist, however if I want more atomic updates, it may be useful to keep the broadcast's +// buffer and return an html component that requests a complete rerender if the handler lagged +/// A container struct for keeping access to the channel senders for both channels used in the sse +/// pipeline +/// +/// For something wishing to listen in on the broadcast html stream, you should call `.subscribe()` +/// on ada_sender +/// +/// Anything wishing to send to sse should pass an [SseMessage] to the [tokio::sync::mpsc::Sender] +/// in sse_sender #[derive(Debug, Clone)] pub struct SseHandler { pub ada_sender: tokio::sync::broadcast::Sender, @@ -10,6 +21,8 @@ pub struct SseHandler { } impl SseHandler { + /// This function initializes the channels used for sse, as well as spawning a manager task for + /// handling sse messages pub fn init() -> Self { let (ada_sender, _) = tokio::sync::broadcast::channel(10); let (sse_sender, mut sse_receiver) = tokio::sync::mpsc::channel(10); @@ -37,6 +50,7 @@ impl SseHandler { } async fn get_ada_list() -> String { + // TODO: need to scope out if these errors need to be handled let mut buf = Vec::new(); crate::templates::components::ada_list_html(&mut buf).unwrap();