DONE we have now intro state separate from others completely

This commit is contained in:
filipriec
2025-04-14 20:00:02 +02:00
parent 7cbe5ce8be
commit e31138c250
6 changed files with 35 additions and 30 deletions

View File

@@ -6,6 +6,7 @@ use crate::state::app::state::AppState;
use crate::state::pages::form::FormState;
use crate::state::pages::auth::LoginState;
use crate::state::pages::auth::RegisterState;
use crate::state::pages::intro::IntroState;
use crate::state::pages::admin::AdminState;
use crate::state::pages::canvas_state::CanvasState;
use crate::ui::handlers::context::UiContext;
@@ -18,6 +19,7 @@ pub async fn handle_navigation_event(
app_state: &mut AppState,
login_state: &mut LoginState,
register_state: &mut RegisterState,
intro_state: &mut IntroState,
admin_state: &mut AdminState,
command_mode: &mut bool,
command_input: &mut String,
@@ -26,19 +28,19 @@ pub async fn handle_navigation_event(
if let Some(action) = config.get_general_action(key.code, key.modifiers) {
match action {
"move_up" => {
move_up(app_state, login_state, register_state, admin_state);
move_up(app_state, login_state, register_state, intro_state, admin_state);
return Ok(EventOutcome::Ok(String::new()));
}
"move_down" => {
move_down(app_state, admin_state);
move_down(app_state, intro_state, admin_state);
return Ok(EventOutcome::Ok(String::new()));
}
"next_option" => {
next_option(app_state);
next_option(app_state, intro_state);
return Ok(EventOutcome::Ok(String::new()));
}
"previous_option" => {
previous_option(app_state);
previous_option(app_state, intro_state);
return Ok(EventOutcome::Ok(String::new()));
}
"toggle_sidebar" => {
@@ -61,7 +63,7 @@ pub async fn handle_navigation_event(
}
"select" => {
let (context, index) = if app_state.ui.show_intro {
(UiContext::Intro, app_state.ui.intro_state.selected_option)
(UiContext::Intro, intro_state.selected_option)
} else if app_state.ui.show_login && app_state.ui.focus_outside_canvas {
(UiContext::Login, app_state.focused_button_index)
} else if app_state.ui.show_register && app_state.ui.focus_outside_canvas {
@@ -81,7 +83,7 @@ pub async fn handle_navigation_event(
Ok(EventOutcome::Ok(String::new()))
}
pub fn move_up(app_state: &mut AppState, login_state: &mut LoginState, register_state: &mut RegisterState, admin_state: &mut AdminState) {
pub fn move_up(app_state: &mut AppState, login_state: &mut LoginState, register_state: &mut RegisterState, intro_state: &mut IntroState, admin_state: &mut AdminState) {
if app_state.ui.focus_outside_canvas && app_state.ui.show_login || app_state.ui.show_register{
if app_state.focused_button_index == 0 {
app_state.ui.focus_outside_canvas = false;
@@ -96,28 +98,28 @@ pub fn move_up(app_state: &mut AppState, login_state: &mut LoginState, register_
app_state.focused_button_index = app_state.focused_button_index.saturating_sub(1);
}
} else if app_state.ui.show_intro {
app_state.ui.intro_state.previous_option();
intro_state.previous_option();
} else if app_state.ui.show_admin {
admin_state.previous();
}
}
pub fn move_down(app_state: &mut AppState, admin_state: &mut AdminState) {
pub fn move_down(app_state: &mut AppState, intro_state: &mut IntroState, admin_state: &mut AdminState) {
if app_state.ui.focus_outside_canvas && app_state.ui.show_login || app_state.ui.show_register {
let num_general_elements = 2;
if app_state.focused_button_index < num_general_elements - 1 {
app_state.focused_button_index += 1;
}
} else if app_state.ui.show_intro {
app_state.ui.intro_state.next_option();
intro_state.next_option();
} else if app_state.ui.show_admin {
admin_state.next();
}
}
pub fn next_option(app_state: &mut AppState) { // Remove option_count parameter
pub fn next_option(app_state: &mut AppState, intro_state: &mut IntroState) {
if app_state.ui.show_intro {
app_state.ui.intro_state.next_option();
intro_state.next_option();
} else {
// Get option count from state instead of parameter
let option_count = app_state.profile_tree.profiles.len();
@@ -125,9 +127,9 @@ pub fn next_option(app_state: &mut AppState) { // Remove option_count parameter
}
}
pub fn previous_option(app_state: &mut AppState) {
pub fn previous_option(app_state: &mut AppState, intro_state: &mut IntroState) {
if app_state.ui.show_intro {
app_state.ui.intro_state.previous_option();
intro_state.previous_option();
} else {
let option_count = app_state.profile_tree.profiles.len();
app_state.focused_button_index = if app_state.focused_button_index == 0 {

View File

@@ -10,6 +10,7 @@ use crate::state::pages::form::FormState;
use crate::state::pages::auth::AuthState;
use crate::state::pages::auth::LoginState;
use crate::state::pages::auth::RegisterState;
use crate::state::pages::intro::IntroState;
use crate::state::pages::admin::AdminState;
use crate::state::app::state::AppState;
use crate::state::pages::canvas_state::CanvasState;
@@ -70,6 +71,7 @@ impl EventHandler {
auth_state: &mut AuthState,
login_state: &mut LoginState,
register_state: &mut RegisterState,
intro_state: &mut IntroState,
admin_state: &mut AdminState,
app_state: &mut AppState,
total_count: u64,
@@ -109,6 +111,7 @@ impl EventHandler {
app_state,
login_state,
register_state,
intro_state,
admin_state,
&mut self.command_mode,
&mut self.command_input,

View File

@@ -2,7 +2,6 @@
use std::env;
use common::proto::multieko2::table_definition::ProfileTreeResponse;
use crate::state::pages::intro::IntroState;
use crate::modes::handlers::mode_manager::AppMode;
use crate::ui::handlers::context::DialogPurpose;
@@ -22,7 +21,6 @@ pub struct UiState {
pub show_form: bool,
pub show_login: bool,
pub show_register: bool,
pub intro_state: IntroState,
pub focus_outside_canvas: bool,
pub dialog: DialogState,
}
@@ -138,7 +136,6 @@ impl Default for UiState {
show_form: false,
show_login: false,
show_register: false,
intro_state: IntroState::new(),
focus_outside_canvas: false,
dialog: DialogState::default(),
}

View File

@@ -1,6 +1,7 @@
// src/tui/functions/intro.rs
use crate::state::app::state::AppState;
pub fn handle_intro_selection(app_state: &mut AppState, index: usize) { // Add index parameter
pub fn handle_intro_selection(app_state: &mut AppState, index: usize) {
match index { // Use index directly
0 => { // Continue
app_state.ui.show_form = true;

View File

@@ -16,6 +16,7 @@ use crate::state::pages::form::FormState;
use crate::state::pages::auth::AuthState;
use crate::state::pages::auth::LoginState;
use crate::state::pages::auth::RegisterState;
use crate::state::pages::intro::IntroState;
use crate::state::app::state::AppState;
use crate::state::pages::admin::AdminState;
@@ -25,6 +26,7 @@ pub fn render_ui(
auth_state: &mut AuthState,
login_state: &LoginState,
register_state: &RegisterState,
intro_state: &IntroState,
admin_state: &mut AdminState,
theme: &Theme,
is_edit_mode: bool,
@@ -49,7 +51,7 @@ pub fn render_ui(
let main_content_area = root[0];
if app_state.ui.show_intro {
render_intro(f, &app_state.ui.intro_state, main_content_area, theme);
render_intro(f, intro_state, main_content_area, theme);
} else if app_state.ui.show_register {
render_register(
f,

View File

@@ -13,6 +13,7 @@ use crate::state::pages::auth::AuthState;
use crate::state::pages::auth::LoginState;
use crate::state::pages::auth::RegisterState;
use crate::state::pages::admin::AdminState;
use crate::state::pages::intro::IntroState;
use crate::state::app::state::AppState;
// Import SaveOutcome
use crate::tui::terminal::{EventReader, TerminalCore};
@@ -21,30 +22,27 @@ use crossterm::cursor::SetCursorStyle;
pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::load()?;
let theme = Theme::from_str(&config.colors.theme);
let mut terminal = TerminalCore::new()?;
let mut grpc_client = GrpcClient::new().await?;
let mut command_handler = CommandHandler::new();
let theme = Theme::from_str(&config.colors.theme);
let mut auth_state = AuthState::default();
let mut register_state = RegisterState::default();
let mut login_state = LoginState::default();
let mut admin_state = AdminState::default();
// Initialize app_state first
let mut event_handler = EventHandler::new().await?;
let event_reader = EventReader::new();
let mut auth_state = AuthState::default();
let mut login_state = LoginState::default();
let mut register_state = RegisterState::default();
let mut intro_state = IntroState::default();
let mut admin_state = AdminState::default();
let mut app_state = AppState::new()?;
// Initialize app state with profile tree and table structure
let column_names =
UiService::initialize_app_state(&mut grpc_client, &mut app_state)
.await?;
// Initialize FormState with dynamic fields
let mut form_state = FormState::new(column_names);
// Initialize EventHandler (which now contains AuthClient)
let mut event_handler = EventHandler::new().await?;
let event_reader = EventReader::new();
// Fetch the total count of Adresar entries
UiService::initialize_adresar_count(&mut grpc_client, &mut app_state)
.await?;
@@ -61,6 +59,7 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
&mut auth_state,
&login_state,
&register_state,
&intro_state,
&mut admin_state,
&theme,
is_edit_mode,
@@ -121,6 +120,7 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
&mut auth_state,
&mut login_state,
&mut register_state,
&mut intro_state,
&mut admin_state,
&mut app_state,
total_count,