diff --git a/client/src/components/handlers.rs b/client/src/components/handlers.rs index 8c26c30..5fd4b82 100644 --- a/client/src/components/handlers.rs +++ b/client/src/components/handlers.rs @@ -5,6 +5,7 @@ pub mod status_line; pub mod canvas; pub mod sidebar; pub mod background; +pub mod intro; pub use command_line::render_command_line; pub use form::*; @@ -12,3 +13,4 @@ pub use status_line::render_status_line; pub use canvas::*; pub use sidebar::*; pub use background::*; +pub use intro::*; diff --git a/client/src/components/handlers/intro.rs b/client/src/components/handlers/intro.rs index 43dbed5..7ef768b 100644 --- a/client/src/components/handlers/intro.rs +++ b/client/src/components/handlers/intro.rs @@ -4,6 +4,7 @@ use ratatui::{ style::Style, text::{Line, Span}, widgets::{Block, BorderType, Borders, Paragraph}, + prelude::Margin, Frame, }; use crate::config::colors::Theme; @@ -51,7 +52,10 @@ impl IntroState { let button_area = Layout::default() .direction(Direction::Horizontal) .constraints([Constraint::Percentage(50), Constraint::Percentage(50)]) - .split(chunks[1].inner(chunks[1])); + .split(chunks[1].inner(Margin { + horizontal: 1, + vertical: 1 + })); self.render_button( f, diff --git a/client/src/modes/handlers/event.rs b/client/src/modes/handlers/event.rs index 2612612..1d73102 100644 --- a/client/src/modes/handlers/event.rs +++ b/client/src/modes/handlers/event.rs @@ -1,6 +1,5 @@ -// - -use crossterm::event::Event; +// src/modes/handlers/event.rs +use crossterm::event::{Event, KeyCode}; use crossterm::cursor::SetCursorStyle; use crate::tui::terminal::{ core::TerminalCore, @@ -48,21 +47,41 @@ impl EventHandler { app_state: &mut crate::state::state::AppState, total_count: u64, current_position: &mut u64, + intro_state: &mut crate::components::handlers::intro::IntroState, ) -> Result<(bool, String), Box> { + if app_state.ui.show_intro { + if let Event::Key(key) = event { + match key.code { + KeyCode::Left => intro_state.previous_option(), + KeyCode::Right => intro_state.next_option(), + KeyCode::Enter => { + if intro_state.selected_option == 0 { + app_state.ui.show_intro = false; + } else { + self.command_message = "Admin panel coming soon".to_string(); + } + return Ok((false, String::new())); + } + _ => {} + } + } + return Ok((false, String::new())); + } + if let Event::Key(key) = event { let key_code = key.code; let modifiers = key.modifiers; - if UiStateHandler::toggle_sidebar( - &mut app_state.ui, - config, - key_code, - modifiers, - ) { - return Ok((false, format!("Sidebar {}", - if app_state.ui.show_sidebar { "shown" } else { "hidden" } - ))); - } + if UiStateHandler::toggle_sidebar( + &mut app_state.ui, + config, + key_code, + modifiers, + ) { + return Ok((false, format!("Sidebar {}", + if app_state.ui.show_sidebar { "shown" } else { "hidden" } + ))); + } if let Some(action) = config.get_action_for_key_in_mode( &config.keybindings.common, diff --git a/client/src/state/state.rs b/client/src/state/state.rs index 600a736..97b1061 100644 --- a/client/src/state/state.rs +++ b/client/src/state/state.rs @@ -6,7 +6,7 @@ use common::proto::multieko2::table_definition::ProfileTreeResponse; pub struct UiState { pub show_sidebar: bool, pub is_saved: bool, -// pub show_intro: bool, + pub show_intro: bool, } pub struct AppState { @@ -49,6 +49,7 @@ impl Default for UiState { Self { show_sidebar: true, is_saved: false, + show_intro: true, } } } diff --git a/client/src/ui/handlers/render.rs b/client/src/ui/handlers/render.rs index 42e26ca..956c2fc 100644 --- a/client/src/ui/handlers/render.rs +++ b/client/src/ui/handlers/render.rs @@ -1,9 +1,9 @@ // src/ui/handlers/render.rs use crate::components::{ - render_background, - render_command_line, + render_background, + render_command_line, render_status_line, - handlers::sidebar::{self, calculate_sidebar_layout} + handlers::{sidebar::{self, calculate_sidebar_layout}, intro}, }; use crate::config::colors::Theme; use ratatui::layout::{Constraint, Direction, Layout}; @@ -23,9 +23,15 @@ pub fn render_ui( command_mode: bool, command_message: &str, app_state: &AppState, + intro_state: &intro::IntroState, ) { render_background(f, f.area(), theme); + if app_state.ui.show_intro { + intro_state.render(f, f.area(), theme); + return; + } + let root = Layout::default() .direction(Direction::Vertical) .constraints([ diff --git a/client/src/ui/handlers/ui.rs b/client/src/ui/handlers/ui.rs index bf0851d..3618575 100644 --- a/client/src/ui/handlers/ui.rs +++ b/client/src/ui/handlers/ui.rs @@ -9,7 +9,7 @@ use crate::config::config::Config; use crate::ui::handlers::{form::FormState, render::render_ui}; use crate::modes::handlers::event::EventHandler; use crate::state::state::AppState; - +use crate::components::handlers::intro::IntroState; pub async fn run_ui() -> Result<(), Box> { let config = Config::load()?; @@ -17,6 +17,7 @@ pub async fn run_ui() -> Result<(), Box> { let mut grpc_client = GrpcClient::new().await?; let mut command_handler = CommandHandler::new(); let theme = Theme::from_str(&config.colors.theme); + let mut intro_state = IntroState::new(); // Fetch table structure at startup (one-time) // TODO: Later, consider implementing a live update for table structure changes. @@ -63,6 +64,7 @@ pub async fn run_ui() -> Result<(), Box> { event_handler.command_mode, &event_handler.command_message, &app_state, + &intro_state, ); })?; @@ -80,6 +82,7 @@ pub async fn run_ui() -> Result<(), Box> { &mut app_state, total_count, &mut current_position, + &mut intro_state, ).await?; app_state.current_position = current_position;