From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <yew-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 654AE1FF187 for <inbox@lore.proxmox.com>; Wed, 7 May 2025 11:10:58 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id EAA0637390; Wed, 7 May 2025 11:11:15 +0200 (CEST) From: Dominik Csapak <d.csapak@proxmox.com> To: yew-devel@lists.proxmox.com Date: Wed, 7 May 2025 11:11:09 +0200 Message-Id: <20250507091112.1145019-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.021 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [wizard.rs] Subject: [yew-devel] [PATCH yew-comp v2 1/4] wizard: move page valid/lock data into WizardState X-BeenThere: yew-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Yew framework devel list at Proxmox <yew-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/yew-devel>, <mailto:yew-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/yew-devel/> List-Post: <mailto:yew-devel@lists.proxmox.com> List-Help: <mailto:yew-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel>, <mailto:yew-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Yew framework devel list at Proxmox <yew-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: yew-devel-bounces@lists.proxmox.com Sender: "yew-devel" <yew-devel-bounces@lists.proxmox.com> It fits better there, and we now have the ability to check this data from the state. (Validity was already possible via the form context, but it was a bit tedious). No functional change intended. Signed-off-by: Dominik Csapak <d.csapak@proxmox.com> --- changes from v1: * fix typo in commit message src/wizard.rs | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/wizard.rs b/src/wizard.rs index c7f9ff6..b816136 100644 --- a/src/wizard.rs +++ b/src/wizard.rs @@ -257,6 +257,8 @@ struct WizardState { page: Option<Key>, page_data: HashMap<Key, FormContext>, page_list: Vec<Key>, + pages_valid: HashSet<Key>, + pages_lock: HashSet<Key>, submit_callbacks: HashMap<Key, Callback<(), bool>>, } @@ -275,6 +277,16 @@ impl WizardState { pub fn get_callback(&self, key: Option<&Key>) -> Option<Callback<(), bool>> { key.and_then(|key| self.submit_callbacks.get(key).cloned()) } + + /// Returns if the page for the given [`Key`] is valid + pub fn page_valid(&self, key: &Key) -> bool { + self.pages_valid.contains(key) + } + + /// Returns if the page for the given [`Key`] is locked + pub fn page_locked(&self, key: &Key) -> bool { + self.pages_lock.contains(key) + } } impl WizardController { @@ -284,6 +296,8 @@ impl WizardController { page: None, page_data: HashMap::new(), page_list: Vec::new(), + pages_valid: HashSet::new(), + pages_lock: HashSet::new(), submit_callbacks: HashMap::new(), }; Self { @@ -316,8 +330,6 @@ pub struct PwtWizard { selection: Selection, loading: bool, // set during submit submit_error: Option<String>, - pages_valid: HashSet<Key>, - pages_lock: HashSet<Key>, valid_data: Rc<Value>, controller: WizardController, @@ -354,8 +366,6 @@ impl Component for PwtWizard { Self { loading: false, submit_error: None, - pages_valid: HashSet::new(), - pages_lock: HashSet::new(), selection, valid_data: Rc::new(json!({})), controller, @@ -507,10 +517,10 @@ impl Component for PwtWizard { let tab_bar_item = page.tab_bar_item.clone().disabled(disabled); if !disabled { - if !self.pages_valid.contains(key) { + if !self.controller.read().page_valid(key) { disabled = true; } - if self.pages_lock.contains(key) { + if self.controller.read().page_locked(key) { disabled = true; } } @@ -541,18 +551,20 @@ impl Component for PwtWizard { impl PwtWizard { fn change_page_valid(&mut self, page: &Key, valid: bool) { + let mut state = self.controller.write(); if valid { - self.pages_valid.insert(page.clone()); + state.pages_valid.insert(page.clone()); } else { - self.pages_valid.remove(page); + state.pages_valid.remove(page); } } fn change_page_lock(&mut self, page: &Key, lock: bool) { + let mut state = self.controller.write(); if lock { - self.pages_lock.insert(page.clone()); + state.pages_lock.insert(page.clone()); } else { - self.pages_lock.remove(page); + state.pages_lock.remove(page); } } -- 2.39.5 _______________________________________________ yew-devel mailing list yew-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel