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 [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id A4C311FF187 for <inbox@lore.proxmox.com>; Wed, 7 May 2025 11:11:28 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D7FD6373FD; Wed, 7 May 2025 11:11:45 +0200 (CEST) From: Dominik Csapak <d.csapak@proxmox.com> To: yew-devel@lists.proxmox.com Date: Wed, 7 May 2025 11:11:10 +0200 Message-Id: <20250507091112.1145019-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250507091112.1145019-1-d.csapak@proxmox.com> References: <20250507091112.1145019-1-d.csapak@proxmox.com> 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 2/4] wizard: factor out 'can progress' logic check to 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> with that we have a single point where we can check if the current form/page state should allow us to progress. The existing logic was reversed to get a 'positive' variable (can_progress vs next_is_disabled), so we have to adapt the used variable names and checks a bit. No functional change intended. Signed-off-by: Dominik Csapak <d.csapak@proxmox.com> --- no changes in v2 src/wizard.rs | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/wizard.rs b/src/wizard.rs index b816136..e33d3c6 100644 --- a/src/wizard.rs +++ b/src/wizard.rs @@ -287,6 +287,30 @@ impl WizardState { pub fn page_locked(&self, key: &Key) -> bool { self.pages_lock.contains(key) } + + fn can_progress(&self) -> bool { + let mut next_enabled = true; + let last_page = self.page_list.last().cloned(); + for i in 0..=self.get_current_index().unwrap_or(0) { + match self.page_list.get(i) { + None => { + next_enabled = false; + break; + } + Some(key) => { + if !self.page_valid(key) && Some(key) != last_page.as_ref() { + next_enabled = false; + break; + } + if self.page_locked(key) { + next_enabled = false; + break; + } + } + } + } + next_enabled + } } impl WizardController { @@ -611,28 +635,10 @@ impl PwtWizard { Some(key) => props.pages.get_index_of(key).unwrap_or(0), }; - let mut next_is_disabled = false; - for i in 0..=page_num { - match props.pages.get_index(i) { - None => { - next_is_disabled = true; - break; - } - Some((key, _)) => { - if !self.pages_valid.contains(key) && Some(key) != last_page.as_ref() { - next_is_disabled = true; - break; - } - if self.pages_lock.contains(key) { - next_is_disabled = true; - break; - } - } - } - } + let mut next_is_enabled = state.can_progress(); if self.loading { - next_is_disabled = true; + next_is_enabled = false; } let next_page = props @@ -675,7 +681,7 @@ impl PwtWizard { .with_child( Button::new(next_button_text) .class(ColorScheme::Primary) - .disabled(next_is_disabled) + .disabled(!next_is_enabled) .onclick({ let link = ctx.link().clone(); let next_page = next_page.clone(); -- 2.39.5 _______________________________________________ yew-devel mailing list yew-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel