[pdm-devel] [PATCH datacenter-manager v3 13/18] ui: add view list context

Dominik Csapak d.csapak at proxmox.com
Mon Nov 17 13:44:35 CET 2025


This wraps SharedState so that we can trigger a reload of the views
in 'main' from a component below without having to pass through a
callback.

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 ui/src/lib.rs               |  3 +++
 ui/src/view_list_context.rs | 31 +++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)
 create mode 100644 ui/src/view_list_context.rs

diff --git a/ui/src/lib.rs b/ui/src/lib.rs
index 98761e00..27a51084 100644
--- a/ui/src/lib.rs
+++ b/ui/src/lib.rs
@@ -45,6 +45,9 @@ pub use load_result::LoadResult;
 mod tasks;
 pub use tasks::register_pve_tasks;
 
+mod view_list_context;
+pub use view_list_context::ViewListContext;
+
 pub fn pdm_client() -> pdm_client::PdmClient<std::rc::Rc<proxmox_yew_comp::HttpClientWasm>> {
     pdm_client::PdmClient(proxmox_yew_comp::CLIENT.with(|c| std::rc::Rc::clone(&c.borrow())))
 }
diff --git a/ui/src/view_list_context.rs b/ui/src/view_list_context.rs
new file mode 100644
index 00000000..c0e4a36e
--- /dev/null
+++ b/ui/src/view_list_context.rs
@@ -0,0 +1,31 @@
+use pwt::state::{SharedState, SharedStateObserver};
+use yew::Callback;
+
+#[derive(PartialEq, Clone)]
+/// Provides a context for updating and listening to changes of the list of views
+pub struct ViewListContext {
+    state: SharedState<usize>,
+}
+
+impl ViewListContext {
+    /// Create a new context
+    pub fn new() -> Self {
+        Self {
+            state: SharedState::new(0),
+        }
+    }
+
+    /// Add a listener to the view list context
+    pub fn add_listener(
+        &self,
+        cb: impl Into<Callback<SharedState<usize>>>,
+    ) -> SharedStateObserver<usize> {
+        self.state.add_listener(cb)
+    }
+
+    /// Triggers an update of the view list for the main menu
+    pub fn update_views(&self) {
+        let mut state = self.state.write();
+        **state = state.saturating_add(1);
+    }
+}
-- 
2.47.3





More information about the pdm-devel mailing list