event.rs and ui.rs refactor for the forms page(moved logic to the forms page dir and just calling it now)
This commit is contained in:
@@ -16,6 +16,7 @@ use crate::pages::admin::AdminState;
|
||||
use crate::pages::admin::AdminFocus;
|
||||
use crate::pages::intro::IntroState;
|
||||
use crate::pages::forms::{FormState, FieldDefinition};
|
||||
use crate::pages::forms;
|
||||
use crate::pages::routing::{Router, Page};
|
||||
use crate::buffer::state::BufferState;
|
||||
use crate::buffer::state::AppView;
|
||||
@@ -459,7 +460,7 @@ pub async fn run_ui() -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
if let Page::Form(current_path) = &router.current {
|
||||
if let Page::Form(_current_path) = &router.current {
|
||||
let current_view_profile = app_state.current_view_profile_name.clone();
|
||||
let current_view_table = app_state.current_view_table_name.clone();
|
||||
|
||||
@@ -475,52 +476,16 @@ pub async fn run_ui() -> Result<()> {
|
||||
);
|
||||
needs_redraw = true;
|
||||
|
||||
match UiService::load_table_view(
|
||||
// DELEGATE to the forms loader
|
||||
match forms::loader::ensure_form_loaded_and_count(
|
||||
&mut grpc_client,
|
||||
&mut app_state,
|
||||
&config,
|
||||
prof_name,
|
||||
tbl_name,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(new_form_state) => {
|
||||
// Set the new form state and fetch count
|
||||
let path = format!("{}/{}", prof_name, tbl_name);
|
||||
app_state.ensure_form_editor(&path, &config, || new_form_state);
|
||||
|
||||
if let Some(form_state) = app_state.form_state_for_path(&path) {
|
||||
if let Err(e) = UiService::fetch_and_set_table_count(
|
||||
&mut grpc_client,
|
||||
form_state,
|
||||
)
|
||||
.await
|
||||
{
|
||||
app_state.update_dialog_content(
|
||||
&format!("Error fetching count: {}", e),
|
||||
vec!["OK".to_string()],
|
||||
DialogPurpose::LoginFailed,
|
||||
);
|
||||
} else if form_state.total_count > 0 {
|
||||
if let Err(e) = UiService::load_table_data_by_position(
|
||||
&mut grpc_client,
|
||||
form_state,
|
||||
)
|
||||
.await
|
||||
{
|
||||
app_state.update_dialog_content(
|
||||
&format!("Error loading data: {}", e),
|
||||
vec!["OK".to_string()],
|
||||
DialogPurpose::LoginFailed,
|
||||
);
|
||||
} else {
|
||||
app_state.hide_dialog();
|
||||
}
|
||||
} else {
|
||||
form_state.reset_to_empty();
|
||||
app_state.hide_dialog();
|
||||
}
|
||||
}
|
||||
|
||||
).await {
|
||||
Ok(()) => {
|
||||
app_state.hide_dialog();
|
||||
prev_view_profile_name = current_view_profile;
|
||||
prev_view_table_name = current_view_table;
|
||||
table_just_switched = true;
|
||||
@@ -531,10 +496,9 @@ pub async fn run_ui() -> Result<()> {
|
||||
vec!["OK".to_string()],
|
||||
DialogPurpose::LoginFailed,
|
||||
);
|
||||
app_state.current_view_profile_name =
|
||||
prev_view_profile_name.clone();
|
||||
app_state.current_view_table_name =
|
||||
prev_view_table_name.clone();
|
||||
// Reset to previous state on error
|
||||
app_state.current_view_profile_name = prev_view_profile_name.clone();
|
||||
app_state.current_view_table_name = prev_view_table_name.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user