From: Dominik Csapak <d.csapak@proxmox.com>
To: yew-devel@lists.proxmox.com
Subject: [yew-devel] [PATCH yew-comp 1/2] tasks: improve behavior of loading additional tasks
Date: Wed, 7 May 2025 16:37:59 +0200 [thread overview]
Message-ID: <20250507143800.3461963-4-d.csapak@proxmox.com> (raw)
In-Reply-To: <20250507143800.3461963-1-d.csapak@proxmox.com>
currently, the task list gets refreshed any of the last 20 entries in
the store get rendered. This also happens though when e.g. the selection
changes or other things cause a redraw even if the position in the list
did not change, which cause unnecessary reloads.
Instead, use the scroll callback of DataTable to only load additional
task when the users scrolls into the last 500px (20 rows would be >600px
for the Desktop theme, and <480px for the crisp theme, so 500px is a
good middle ground).
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/tasks.rs | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/src/tasks.rs b/src/tasks.rs
index 67fa7b1..3c531c1 100644
--- a/src/tasks.rs
+++ b/src/tasks.rs
@@ -10,6 +10,8 @@ use pwt::widget::form::{Field, Form, FormContext, InputType};
use gloo_timers::callback::Timeout;
use html::IntoEventCallback;
use serde_json::Map;
+use wasm_bindgen::JsCast;
+use web_sys::HtmlElement;
use yew::html::IntoPropValue;
use yew::virtual_dom::{VComp, VNode};
@@ -32,7 +34,7 @@ use super::{TaskStatusSelector, TaskTypeSelector};
const FILTER_UPDATE_BUFFER_MS: u32 = 150;
const BATCH_LIMIT: u64 = 500;
-const LOAD_BUFFER_ROWS: usize = 20;
+const LOAD_BUFFER_PX: i32 = 500;
#[derive(PartialEq, Properties)]
#[builder]
@@ -168,12 +170,7 @@ impl LoadableComponent for ProxmoxTasks {
FormContext::new().on_change(ctx.link().callback(|_| Msg::UpdateFilter));
let row_render_callback = DataTableRowRenderCallback::new({
- let store = store.clone();
- let link = link.clone();
move |args: &mut _| {
- if args.row_index() > store.data_len().saturating_sub(LOAD_BUFFER_ROWS) {
- link.send_message(Msg::LoadBatch(store.data_len() as u64));
- }
let record: &TaskListItem = args.record();
match record.status.as_deref() {
Some("RUNNING" | "OK") | None => {}
@@ -399,6 +396,22 @@ impl LoadableComponent for ProxmoxTasks {
DataTable::new(columns, self.store.clone())
.class("pwt-flex-fit")
.selection(self.selection.clone())
+ .on_table_scroll({
+ let link = ctx.link().clone();
+ let store = self.store.clone();
+ move |event: Event| {
+ if let Some(target) = event
+ .target()
+ .and_then(|target| target.dyn_into::<HtmlElement>().ok())
+ {
+ if target.scroll_height() - (target.scroll_top() + target.client_height())
+ < LOAD_BUFFER_PX
+ {
+ link.send_message(Msg::LoadBatch(store.data_len() as u64));
+ }
+ }
+ }
+ })
.on_row_dblclick(move |_: &mut _| {
link.send_message(Msg::ShowTask);
})
--
2.39.5
_______________________________________________
yew-devel mailing list
yew-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel
next prev parent reply other threads:[~2025-05-07 14:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-07 14:37 [yew-devel] [PATCH yew-comp/yew-widget-toolkit 0/4] fix crash and improve task loading Dominik Csapak
2025-05-07 14:37 ` [yew-devel] [PATCH yew-widget-toolkit 1/2] fix #6382: widget: data table: prevent duplicate yew keys for rows Dominik Csapak
2025-05-08 8:50 ` Dietmar Maurer
2025-05-07 14:37 ` [yew-devel] [PATCH yew-widget-toolkit 2/2] widget: data table: add table scroll callback Dominik Csapak
2025-05-08 9:08 ` [yew-devel] applied: " Dietmar Maurer
2025-05-07 14:37 ` Dominik Csapak [this message]
2025-05-07 14:38 ` [yew-devel] [PATCH yew-comp 2/2] tasks: don't add entries we already loaded Dominik Csapak
2025-05-08 9:32 ` Dietmar Maurer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250507143800.3461963-4-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=yew-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal