adding to have multiple forms pages
This commit is contained in:
@@ -113,13 +113,15 @@ pub async fn run_ui() -> Result<()> {
|
||||
.collect();
|
||||
|
||||
// Replace local form_state with app_state.form_editor
|
||||
app_state.set_form_state(
|
||||
FormState::new(initial_profile.clone(), initial_table.clone(), initial_field_defs),
|
||||
&config,
|
||||
);
|
||||
let path = format!("{}/{}", initial_profile, initial_table);
|
||||
app_state.ensure_form_editor(&path, &config, || {
|
||||
FormState::new(initial_profile.clone(), initial_table.clone(), initial_field_defs)
|
||||
});
|
||||
buffer_state.update_history(AppView::Form(path.clone()));
|
||||
router.navigate(Page::Form(path));
|
||||
|
||||
// Fetch initial count using app_state accessor
|
||||
if let Some(form_state) = app_state.form_state_mut() {
|
||||
if let Some(form_state) = app_state.active_form_state_mut(&buffer_state) {
|
||||
UiService::fetch_and_set_table_count(&mut grpc_client, form_state)
|
||||
.await
|
||||
.context(format!(
|
||||
@@ -137,7 +139,9 @@ pub async fn run_ui() -> Result<()> {
|
||||
}
|
||||
|
||||
if auto_logged_in {
|
||||
buffer_state.history = vec![AppView::Form];
|
||||
let path = format!("{}/{}", initial_profile, initial_table);
|
||||
buffer_state.history = vec![AppView::Form(path.clone())];
|
||||
router.navigate(Page::Form(path));
|
||||
buffer_state.active_index = 0;
|
||||
info!("Initial view set to Form due to auto-login.");
|
||||
}
|
||||
@@ -150,7 +154,7 @@ pub async fn run_ui() -> Result<()> {
|
||||
let mut table_just_switched = false;
|
||||
|
||||
loop {
|
||||
let position_before_event = app_state.form_state()
|
||||
let position_before_event = app_state.active_form_state_mut(&buffer_state)
|
||||
.map(|fs| fs.current_position)
|
||||
.unwrap_or(1);
|
||||
let mut event_processed = false;
|
||||
@@ -216,7 +220,7 @@ pub async fn run_ui() -> Result<()> {
|
||||
if !overlay_active {
|
||||
if let Page::Form(_) = &router.current {
|
||||
if !app_state.ui.focus_outside_canvas {
|
||||
if let Some(editor) = app_state.form_editor.as_mut() {
|
||||
if let Some(editor) = app_state.active_form_editor_mut(&buffer_state) {
|
||||
match editor.handle_key_event(*key_event) {
|
||||
KeyEventOutcome::Consumed(Some(msg)) => {
|
||||
event_handler.command_message = msg;
|
||||
@@ -725,11 +729,14 @@ pub async fn run_ui() -> Result<()> {
|
||||
|
||||
// Workaround for borrow checker
|
||||
let current_dir = app_state.current_dir.clone();
|
||||
let form_state_clone = app_state.form_state().unwrap().clone();
|
||||
let form_state_clone = if let Page::Form(path) = &router.current {
|
||||
app_state.form_state_for_path(path).cloned()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
terminal
|
||||
.draw(|f| {
|
||||
let mut temp_form_state = form_state_clone.clone();
|
||||
if let Some(form_state_clone) = form_state_clone {
|
||||
terminal.draw(|f| {
|
||||
render_ui(
|
||||
f,
|
||||
&mut router,
|
||||
@@ -746,6 +753,7 @@ pub async fn run_ui() -> Result<()> {
|
||||
})
|
||||
.context("Terminal draw call failed")?;
|
||||
needs_redraw = false;
|
||||
}
|
||||
}
|
||||
|
||||
let now = Instant::now();
|
||||
|
||||
Reference in New Issue
Block a user