usage of the canvas is fully implemented, time to fix bugs. Working now fully
This commit is contained in:
@@ -63,10 +63,22 @@ impl LoginState {
|
|||||||
|
|
||||||
impl RegisterState {
|
impl RegisterState {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
let mut state = Self {
|
||||||
autocomplete: AutocompleteState::new(),
|
autocomplete: AutocompleteState::new(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
};
|
||||||
|
|
||||||
|
// Initialize autocomplete with role suggestions
|
||||||
|
let suggestions: Vec<SuggestionItem<String>> = AVAILABLE_ROLES
|
||||||
|
.iter()
|
||||||
|
.map(|role| SuggestionItem::simple(role.clone(), role.clone()))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
// Set suggestions but keep inactive initially
|
||||||
|
state.autocomplete.set_suggestions(suggestions);
|
||||||
|
state.autocomplete.is_active = false; // Not active by default
|
||||||
|
|
||||||
|
state
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,6 +161,13 @@ impl CanvasState for RegisterState {
|
|||||||
fn set_current_field(&mut self, index: usize) {
|
fn set_current_field(&mut self, index: usize) {
|
||||||
if index < 5 {
|
if index < 5 {
|
||||||
self.current_field = index;
|
self.current_field = index;
|
||||||
|
|
||||||
|
// Auto-activate autocomplete when moving to role field (index 4)
|
||||||
|
if index == 4 && !self.autocomplete.is_active {
|
||||||
|
self.activate_autocomplete();
|
||||||
|
} else if index != 4 && self.autocomplete.is_active {
|
||||||
|
self.deactivate_autocomplete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,4 +254,62 @@ impl AutocompleteCanvasState for RegisterState {
|
|||||||
fn autocomplete_state_mut(&mut self) -> Option<&mut AutocompleteState<Self::SuggestionData>> {
|
fn autocomplete_state_mut(&mut self) -> Option<&mut AutocompleteState<Self::SuggestionData>> {
|
||||||
Some(&mut self.autocomplete)
|
Some(&mut self.autocomplete)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn activate_autocomplete(&mut self) {
|
||||||
|
let current_field = self.current_field();
|
||||||
|
if self.supports_autocomplete(current_field) {
|
||||||
|
self.autocomplete.activate(current_field);
|
||||||
|
|
||||||
|
// Re-filter suggestions based on current input
|
||||||
|
let current_input = self.role.to_lowercase();
|
||||||
|
let filtered_suggestions: Vec<SuggestionItem<String>> = AVAILABLE_ROLES
|
||||||
|
.iter()
|
||||||
|
.filter(|role| role.to_lowercase().contains(¤t_input))
|
||||||
|
.map(|role| SuggestionItem::simple(role.clone(), role.clone()))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
self.autocomplete.set_suggestions(filtered_suggestions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deactivate_autocomplete(&mut self) {
|
||||||
|
self.autocomplete.deactivate();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_autocomplete_active(&self) -> bool {
|
||||||
|
self.autocomplete.is_active
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_autocomplete_ready(&self) -> bool {
|
||||||
|
self.autocomplete.is_ready()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn apply_autocomplete_selection(&mut self) -> Option<String> {
|
||||||
|
// First, get the data we need and clone it to avoid borrowing conflicts
|
||||||
|
let selection_info = self.autocomplete.get_selected().map(|selected| {
|
||||||
|
(selected.value_to_store.clone(), selected.display_text.clone())
|
||||||
|
});
|
||||||
|
|
||||||
|
// Now do the mutable operations
|
||||||
|
if let Some((value, display_text)) = selection_info {
|
||||||
|
self.role = value;
|
||||||
|
self.set_has_unsaved_changes(true);
|
||||||
|
self.deactivate_autocomplete();
|
||||||
|
Some(format!("Selected role: {}", display_text))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_autocomplete_suggestions(&mut self, suggestions: Vec<SuggestionItem<Self::SuggestionData>>) {
|
||||||
|
if let Some(state) = self.autocomplete_state_mut() {
|
||||||
|
state.set_suggestions(suggestions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_autocomplete_loading(&mut self, loading: bool) {
|
||||||
|
if let Some(state) = self.autocomplete_state_mut() {
|
||||||
|
state.is_loading = loading;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user