From: Dominik Csapak <d.csapak@proxmox.com>
To: yew-devel@lists.proxmox.com
Subject: [yew-devel] [PATCH yew-comp 1/4] wizard: move page valid/lock data into WizardState
Date: Tue, 6 May 2025 15:26:30 +0200 [thread overview]
Message-ID: <20250506132633.2898717-1-d.csapak@proxmox.com> (raw)
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 function change intended.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
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
next 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 Dominik Csapak [this message]
2025-05-06 13:26 ` [yew-devel] [PATCH yew-comp 2/4] wizard: factor out 'can progress' logic check to WizardState Dominik Csapak
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-1-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