diff --git a/web/src/state.rs b/web/src/state.rs index 00fef7b..f86e294 100644 --- a/web/src/state.rs +++ b/web/src/state.rs @@ -332,6 +332,8 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders) { selected_threads, }; orders.send_msg(Msg::UpdateServerVersion(data.version)); + // Generate signal so progress bar is reset + orders.send_msg(Msg::WindowScrolled); } Msg::ShowThreadRequest { thread_id } => { @@ -382,6 +384,8 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders) { } } orders.send_msg(Msg::UpdateServerVersion(data.version)); + // Generate signal so progress bar is reset + orders.send_msg(Msg::WindowScrolled); } Msg::ShowThreadResult(bad) => { error!("show_thread_query error: {bad:#?}"); @@ -511,9 +515,29 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders) { .value_of(); let r = el.get_bounding_client_rect(); - let end = r.height() - ih; + if r.height() < ih { + // The whole content fits in the window, no scrollbar + orders.send_msg(Msg::SetProgress(0.)); + return; + } + let end: f64 = r.height() - ih; + if end < 0. { + orders.send_msg(Msg::SetProgress(0.)); + return; + } + // Flip Y, normally it's 0-point when the top of the content hits the top of the + // screen and goes negative from there. let y = -r.y(); - orders.send_msg(Msg::SetProgress((y / end).max(0.))); + let ratio: f64 = (y / end).max(0.); + debug!( + "WindowScrolled ih {ih} end {end} ratio {ratio:.02} {}x{} @ {},{}", + r.width(), + r.height(), + r.x(), + r.y() + ); + + orders.send_msg(Msg::SetProgress(ratio)); } else { orders.send_msg(Msg::SetProgress(0.)); }