From 69953401b180cc95edeecffd037029617722c6fc Mon Sep 17 00:00:00 2001 From: filipriec Date: Wed, 16 Apr 2025 22:07:07 +0200 Subject: [PATCH] NEW PAGE ADD TABLE --- client/src/components/admin.rs | 2 ++ client/src/components/admin/add_table.rs | 32 +++++++++++++++++++ client/src/functions/common/buffer.rs | 2 +- .../functions/modes/navigation/admin_nav.rs | 11 ++++--- client/src/modes/handlers/event.rs | 2 ++ client/src/state/app/buffer.rs | 4 ++- client/src/state/app/state.rs | 2 ++ client/src/ui/handlers/ui.rs | 2 ++ 8 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 client/src/components/admin/add_table.rs diff --git a/client/src/components/admin.rs b/client/src/components/admin.rs index 8d35d7b..6cdfafd 100644 --- a/client/src/components/admin.rs +++ b/client/src/components/admin.rs @@ -1,6 +1,8 @@ // src/components/admin.rs pub mod admin_panel; pub mod admin_panel_admin; +pub mod add_table; pub use admin_panel::*; pub use admin_panel_admin::*; +pub use add_table::*; diff --git a/client/src/components/admin/add_table.rs b/client/src/components/admin/add_table.rs new file mode 100644 index 0000000..dd07a48 --- /dev/null +++ b/client/src/components/admin/add_table.rs @@ -0,0 +1,32 @@ +// src/components/admin/add_table.rs +use crate::config::colors::themes::Theme; +use ratatui::{ + layout::{Alignment, Rect}, + style::{Style, Stylize}, + widgets::{Block, Borders, Paragraph}, + Frame, +}; + +/// Renders a placeholder page for adding tables. +pub fn render_add_table_page( + f: &mut Frame, + area: Rect, + theme: &Theme, +) { + let block = Block::default() + .title(" Add New Table ") + .borders(Borders::ALL) + .border_style(Style::default().fg(theme.accent)) + .style(Style::default().bg(theme.bg)); + + let inner_area = block.inner(area); + + let text = Paragraph::new("This is the placeholder page for adding a new table.\n\nDrawing canvas coming soon!") + .style(Style::default().fg(theme.fg)) + .alignment(Alignment::Center); + + f.render_widget(block, area); + f.render_widget(text, inner_area); +} + + diff --git a/client/src/functions/common/buffer.rs b/client/src/functions/common/buffer.rs index af487d9..0e3f7e8 100644 --- a/client/src/functions/common/buffer.rs +++ b/client/src/functions/common/buffer.rs @@ -6,7 +6,7 @@ use crate::state::app::buffer::AppView; pub fn get_view_layer(view: &AppView) -> u8 { match view { AppView::Intro => 1, - AppView::Login | AppView::Register | AppView::Admin => 2, + AppView::Login | AppView::Register | AppView::Admin | AppView::AddTable => 2, AppView::Form(_) | AppView::Scratch => 3, } } diff --git a/client/src/functions/modes/navigation/admin_nav.rs b/client/src/functions/modes/navigation/admin_nav.rs index 8b91afb..b224928 100644 --- a/client/src/functions/modes/navigation/admin_nav.rs +++ b/client/src/functions/modes/navigation/admin_nav.rs @@ -6,14 +6,17 @@ use crate::state::{ pages::admin::{AdminFocus, AdminState}, }; use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; +use crate::state::app::buffer::AppView; +use crate::state::app::buffer::BufferState; /// Handles navigation events specifically for the Admin Panel view. /// Returns true if the event was handled, false otherwise. pub fn handle_admin_navigation( key: KeyEvent, config: &Config, - app_state: &AppState, // Read-only access needed for counts - admin_state: &mut AdminState, // Mutable to change focus/selection + app_state: &AppState, + admin_state: &mut AdminState, + buffer_state: &mut BufferState, command_message: &mut String, ) -> bool { let action = config.get_general_action(key.code, key.modifiers); @@ -157,8 +160,8 @@ pub fn handle_admin_navigation( // TODO: Trigger action for Button 1 } AdminFocus::Button2 => { - *command_message = "Action: Add Table (Not Implemented)".to_string(); - // TODO: Trigger action for Button 2 + buffer_state.update_history(AppView::AddTable); + *command_message = "Navigating to Add Table page...".to_string(); } AdminFocus::Button3 => { *command_message = "Action: Change Table (Not Implemented)".to_string(); diff --git a/client/src/modes/handlers/event.rs b/client/src/modes/handlers/event.rs index 8f51904..38201fc 100644 --- a/client/src/modes/handlers/event.rs +++ b/client/src/modes/handlers/event.rs @@ -104,6 +104,7 @@ impl EventHandler { else if ui.show_login { AppView::Login } else if ui.show_register { AppView::Register } else if ui.show_admin { AppView::Admin } + else if ui.show_add_table { AppView::AddTable } else if ui.show_form { let form_name = app_state.selected_profile.clone().unwrap_or_else(|| "Data Form".to_string()); AppView::Form(form_name) @@ -168,6 +169,7 @@ impl EventHandler { config, app_state, admin_state, + buffer_state, &mut self.command_message, ) { return Ok(EventOutcome::Ok(self.command_message.clone())); diff --git a/client/src/state/app/buffer.rs b/client/src/state/app/buffer.rs index c3f7e71..137847b 100644 --- a/client/src/state/app/buffer.rs +++ b/client/src/state/app/buffer.rs @@ -7,6 +7,7 @@ pub enum AppView { Login, Register, Admin, + AddTable, Form(String), Scratch, } @@ -18,7 +19,8 @@ impl AppView { AppView::Intro => "Intro", AppView::Login => "Login", AppView::Register => "Register", - AppView::Admin => "Admin Panel", + AppView::Admin => "Admin_panel", + AppView::AddTable => "Add_table", AppView::Form(name) => name.as_str(), AppView::Scratch => "*scratch*", } diff --git a/client/src/state/app/state.rs b/client/src/state/app/state.rs index 57dbd1d..b32c2b0 100644 --- a/client/src/state/app/state.rs +++ b/client/src/state/app/state.rs @@ -19,6 +19,7 @@ pub struct UiState { pub show_buffer_list: bool, pub show_intro: bool, pub show_admin: bool, + pub show_add_table: bool, pub show_form: bool, pub show_login: bool, pub show_register: bool, @@ -134,6 +135,7 @@ impl Default for UiState { show_sidebar: false, show_intro: true, show_admin: false, + show_add_table: false, show_form: false, show_login: false, show_register: false, diff --git a/client/src/ui/handlers/ui.rs b/client/src/ui/handlers/ui.rs index af4280a..1aedd4d 100644 --- a/client/src/ui/handlers/ui.rs +++ b/client/src/ui/handlers/ui.rs @@ -67,6 +67,7 @@ pub async fn run_ui() -> Result<(), Box> { app_state.ui.show_login = false; app_state.ui.show_register = false; app_state.ui.show_admin = false; + app_state.ui.show_add_table = false; app_state.ui.show_form = false; match active_view { AppView::Intro => app_state.ui.show_intro = true, @@ -79,6 +80,7 @@ pub async fn run_ui() -> Result<(), Box> { .collect(); admin_state.set_profiles(profile_names); } + AppView::AddTable => app_state.ui.show_add_table = true, AppView::Form(_) => app_state.ui.show_form = true, AppView::Scratch => {} // Or show a scratchpad component }