comments!
parent
cfb9a38c78
commit
3102e77c82
|
@ -129,6 +129,10 @@ async fn drinks(Path(id): Path<u32>) -> impl IntoResponse {
|
|||
}
|
||||
|
||||
async fn shift_report(State(state): State<AppState>, Path(id): Path<u32>) -> 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> = Drink::belonging_to(&shift).load(&mut conn).await.unwrap();
|
||||
|
|
|
@ -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<String>,
|
||||
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue