public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Lukas Wagner <l.wagner@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH proxmox-yew-comp] apt package manager: add distinct message type to avoid spurious subscription popups
Date: Tue,  2 Dec 2025 11:02:39 +0100	[thread overview]
Message-ID: <20251202100239.117392-1-l.wagner@proxmox.com> (raw)

The freshly introduced subscription check works via sending a message to
the component which is then processed by the `update` function. When
implementing, it was overlooked that there is was already a selection
change listener set up to send messages on selection change, which led
to the behavior of triggering the subscription check whenever a package
was selected by the list.

This is fixed by adding a distinct Message enum type with variants for
the selection change event and the check subscription event.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 src/apt_package_manager.rs | 55 +++++++++++++++++++++++---------------
 1 file changed, 33 insertions(+), 22 deletions(-)

diff --git a/src/apt_package_manager.rs b/src/apt_package_manager.rs
index 78e82a0..0b4ae2e 100644
--- a/src/apt_package_manager.rs
+++ b/src/apt_package_manager.rs
@@ -154,6 +154,12 @@ pub enum ViewState {
     ShowSubscriptionPopup,
 }
 
+/// Messages for [`ProxmoxAptManager::update`]
+pub enum Msg {
+    CheckSubscription,
+    SelectionChange,
+}
+
 pub struct ProxmoxAptPackageManager {
     tree_store: TreeStore<TreeEntry>,
     selection: Selection,
@@ -163,13 +169,13 @@ pub struct ProxmoxAptPackageManager {
 
 impl LoadableComponent for ProxmoxAptPackageManager {
     type Properties = AptPackageManager;
-    type Message = ();
+    type Message = Msg;
     type ViewState = ViewState;
 
     fn create(ctx: &LoadableComponentContext<Self>) -> Self {
         let tree_store = TreeStore::new().view_root(false);
         let columns = Self::columns(ctx, tree_store.clone());
-        let selection = Selection::new().on_select(ctx.link().callback(|_| ()));
+        let selection = Selection::new().on_select(ctx.link().callback(|_| Msg::SelectionChange));
 
         Self {
             tree_store,
@@ -179,27 +185,32 @@ impl LoadableComponent for ProxmoxAptPackageManager {
         }
     }
 
-    fn update(&mut self, ctx: &LoadableComponentContext<Self>, _msg: Self::Message) -> bool {
-        let link = ctx.link().clone();
-        let props = ctx.props();
-        let url = props
-            .clone()
-            .subscription_url
-            .unwrap_or("/nodes/localhost/subscription".into());
-        let task_base_url = props.task_base_url.clone();
-        let command = format!("{}/update", props.base_url);
-        self.async_pool.spawn(async move {
-            let data = crate::http_get::<Value>(url.as_str(), None).await;
-            let is_active = subscription_is_active(&Some(data));
+    fn update(&mut self, ctx: &LoadableComponentContext<Self>, msg: Self::Message) -> bool {
+        match msg {
+            Msg::CheckSubscription => {
+                let link = ctx.link().clone();
+                let props = ctx.props();
+                let url = props
+                    .clone()
+                    .subscription_url
+                    .unwrap_or("/nodes/localhost/subscription".into());
+                let task_base_url = props.task_base_url.clone();
+                let command = format!("{}/update", props.base_url);
+                self.async_pool.spawn(async move {
+                    let data = crate::http_get::<Value>(url.as_str(), None).await;
+                    let is_active = subscription_is_active(&Some(data));
 
-            if is_active {
-                link.task_base_url(task_base_url);
-                link.start_task(&command, None, false);
-            } else {
-                link.change_view(Some(ViewState::ShowSubscriptionPopup));
+                    if is_active {
+                        link.task_base_url(task_base_url);
+                        link.start_task(&command, None, false);
+                    } else {
+                        link.change_view(Some(ViewState::ShowSubscriptionPopup));
+                    }
+                });
+                true
             }
-        });
-        true
+            Msg::SelectionChange => true,
+        }
     }
 
     fn load(
@@ -255,7 +266,7 @@ impl LoadableComponent for ProxmoxAptPackageManager {
 
                 move |_| {
                     if sub_check {
-                        link.send_message(());
+                        link.send_message(Msg::CheckSubscription);
                     } else {
                         link.start_task(&command, None, false);
                     }
-- 
2.47.3



_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel


             reply	other threads:[~2025-12-02 10:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-02 10:02 Lukas Wagner [this message]
2025-12-02 12:17 ` [pdm-devel] applied: " Thomas Lamprecht

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=20251202100239.117392-1-l.wagner@proxmox.com \
    --to=l.wagner@proxmox.com \
    --cc=pdm-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal