intro page working properly well
This commit is contained in:
@@ -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::*;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<dyn std::error::Error>> {
|
||||
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,
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::components::{
|
||||
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([
|
||||
|
||||
@@ -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<dyn std::error::Error>> {
|
||||
let config = Config::load()?;
|
||||
@@ -17,6 +17,7 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
||||
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<dyn std::error::Error>> {
|
||||
event_handler.command_mode,
|
||||
&event_handler.command_message,
|
||||
&app_state,
|
||||
&intro_state,
|
||||
);
|
||||
})?;
|
||||
|
||||
@@ -80,6 +82,7 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
||||
&mut app_state,
|
||||
total_count,
|
||||
&mut current_position,
|
||||
&mut intro_state,
|
||||
).await?;
|
||||
|
||||
app_state.current_position = current_position;
|
||||
|
||||
Reference in New Issue
Block a user