web: add scrollbar for read progress
This commit is contained in:
@@ -37,15 +37,36 @@ pub fn init(url: Url, orders: &mut impl Orders<Msg>) -> Model {
|
||||
// 'notmuch new' on the server periodically?
|
||||
orders.stream(streams::interval(30_000, || Msg::RefreshStart));
|
||||
orders.subscribe(on_url_changed);
|
||||
orders.stream(streams::window_event(Ev::Scroll, |_| {
|
||||
compute_scroll_ratio()
|
||||
}));
|
||||
|
||||
Model {
|
||||
context: Context::None,
|
||||
query: "".to_string(),
|
||||
refreshing_state: RefreshingState::None,
|
||||
tags: None,
|
||||
read_completion_ratio: 0.,
|
||||
}
|
||||
}
|
||||
|
||||
fn compute_scroll_ratio() -> Msg {
|
||||
// TODO: compute completion based on contents of the post, not the overall body (which includes
|
||||
// the tags at the end on mobile/tablet).
|
||||
let body = document().body().expect("body");
|
||||
let sh = body.scroll_height() as f64;
|
||||
let window = window();
|
||||
let ih = window
|
||||
.inner_height()
|
||||
.expect("window height")
|
||||
.unchecked_into::<js_sys::Number>()
|
||||
.value_of();
|
||||
let scroll_y = window.scroll_y().expect("scroll Y");
|
||||
|
||||
let end = sh - ih;
|
||||
let ratio = scroll_y / end;
|
||||
Msg::SetProgress(ratio)
|
||||
}
|
||||
fn on_url_changed(uc: subs::UrlChanged) -> Msg {
|
||||
let mut url = uc.0;
|
||||
info!(
|
||||
@@ -489,6 +510,9 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
.expect("failed to copy to clipboard");
|
||||
});
|
||||
}
|
||||
Msg::SetProgress(ratio) => {
|
||||
model.read_completion_ratio = ratio;
|
||||
}
|
||||
}
|
||||
}
|
||||
// `Model` describes our app state.
|
||||
@@ -497,6 +521,7 @@ pub struct Model {
|
||||
pub context: Context,
|
||||
pub refreshing_state: RefreshingState,
|
||||
pub tags: Option<Vec<Tag>>,
|
||||
pub read_completion_ratio: f64,
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
@@ -590,4 +615,6 @@ pub enum Msg {
|
||||
MultiMsg(Vec<Msg>),
|
||||
|
||||
CopyToClipboard(String),
|
||||
|
||||
SetProgress(f64),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user