public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pdm-devel] [PATCH proxmox-yew-comp] apt package manager: add distinct message type to avoid spurious subscription popups
@ 2025-12-02 10:02 Lukas Wagner
  2025-12-02 12:17 ` [pdm-devel] applied: " Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Lukas Wagner @ 2025-12-02 10:02 UTC (permalink / raw)
  To: pdm-devel

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-12-02 12:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-02 10:02 [pdm-devel] [PATCH proxmox-yew-comp] apt package manager: add distinct message type to avoid spurious subscription popups Lukas Wagner
2025-12-02 12:17 ` [pdm-devel] applied: " Thomas Lamprecht

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