router2, needs bug fixes
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::modes::handlers::event::EventHandler;
|
||||
use crate::state::pages::add_logic::AddLogicFocus;
|
||||
use crate::state::pages::admin::AdminState;
|
||||
use crate::pages::routing::{Router, Page};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum AppMode {
|
||||
@@ -28,11 +28,11 @@ impl From<canvas::AppMode> for AppMode {
|
||||
pub struct ModeManager;
|
||||
|
||||
impl ModeManager {
|
||||
/// Determine current mode based on app state
|
||||
/// Determine current mode based on app state + router
|
||||
pub fn derive_mode(
|
||||
app_state: &AppState,
|
||||
event_handler: &EventHandler,
|
||||
admin_state: &AdminState,
|
||||
router: &Router,
|
||||
) -> AppMode {
|
||||
// Navigation palette always forces General
|
||||
if event_handler.navigation_state.active {
|
||||
@@ -44,16 +44,17 @@ impl ModeManager {
|
||||
return AppMode::Command;
|
||||
}
|
||||
|
||||
// Always trust the FormEditor when a form is active
|
||||
if app_state.ui.show_form && !app_state.ui.focus_outside_canvas {
|
||||
if let Some(editor) = &app_state.form_editor {
|
||||
return AppMode::from(editor.mode());
|
||||
match &router.current {
|
||||
// --- Form view ---
|
||||
Page::Form(_) if !app_state.ui.focus_outside_canvas => {
|
||||
if let Some(editor) = &app_state.form_editor {
|
||||
return AppMode::from(editor.mode());
|
||||
}
|
||||
AppMode::General
|
||||
}
|
||||
}
|
||||
|
||||
// --- Non-form views (add_logic, add_table, etc.) ---
|
||||
if app_state.ui.show_add_logic {
|
||||
match admin_state.add_logic_state.current_focus {
|
||||
// --- AddLogic view ---
|
||||
Page::AddLogic(state) => match state.current_focus {
|
||||
AddLogicFocus::InputLogicName
|
||||
| AddLogicFocus::InputTargetColumn
|
||||
| AddLogicFocus::InputDescription => {
|
||||
@@ -64,26 +65,30 @@ impl ModeManager {
|
||||
}
|
||||
}
|
||||
_ => AppMode::General,
|
||||
},
|
||||
|
||||
// --- AddTable view ---
|
||||
Page::AddTable(_) => {
|
||||
if app_state.ui.focus_outside_canvas {
|
||||
AppMode::General
|
||||
} else if event_handler.is_edit_mode {
|
||||
AppMode::Edit
|
||||
} else {
|
||||
AppMode::ReadOnly
|
||||
}
|
||||
}
|
||||
} else if app_state.ui.show_add_table {
|
||||
if app_state.ui.focus_outside_canvas {
|
||||
AppMode::General
|
||||
} else if event_handler.is_edit_mode {
|
||||
AppMode::Edit
|
||||
} else {
|
||||
AppMode::ReadOnly
|
||||
|
||||
// --- Login/Register views ---
|
||||
Page::Login(_) | Page::Register(_) => {
|
||||
if event_handler.is_edit_mode {
|
||||
AppMode::Edit
|
||||
} else {
|
||||
AppMode::ReadOnly
|
||||
}
|
||||
}
|
||||
} else if app_state.ui.show_login
|
||||
|| app_state.ui.show_register
|
||||
{
|
||||
// login/register still use the old flag
|
||||
if event_handler.is_edit_mode {
|
||||
AppMode::Edit
|
||||
} else {
|
||||
AppMode::ReadOnly
|
||||
}
|
||||
} else {
|
||||
AppMode::General
|
||||
|
||||
// --- Everything else (Intro, Admin, etc.) ---
|
||||
_ => AppMode::General,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user