From: Dominik Csapak <d.csapak@proxmox.com>
To: yew-devel@lists.proxmox.com
Subject: [yew-devel] [PATCH yew-comp 2/4] wizard: factor out 'can progress' logic check to WizardState
Date: Tue, 6 May 2025 15:26:31 +0200 [thread overview]
Message-ID: <20250506132633.2898717-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20250506132633.2898717-1-d.csapak@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>
---
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
next prev parent reply other threads:[~2025-05-06 13:26 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-06 13:26 [yew-devel] [PATCH yew-comp 1/4] wizard: move page valid/lock data into WizardState Dominik Csapak
2025-05-06 13:26 ` Dominik Csapak [this message]
2025-05-06 13:26 ` [yew-devel] [PATCH yew-comp 3/4] wizard: optimize enbaled check for next button Dominik Csapak
2025-05-07 8:15 ` Shannon Sterz
2025-05-07 8:23 ` Dominik Csapak
2025-05-06 13:26 ` [yew-devel] [PATCH yew-comp 4/4] wizard: fix form progressing when pressing enter Dominik Csapak
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=20250506132633.2898717-2-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=yew-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