login logic in the components
This commit is contained in:
@@ -1,62 +1,58 @@
|
|||||||
// src/components/auth/login.rs
|
// src/components/auth/login.rs
|
||||||
|
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||||
style::Style,
|
style::Style,
|
||||||
text::{Line, Span},
|
|
||||||
widgets::{Block, BorderType, Borders, Paragraph},
|
widgets::{Block, BorderType, Borders, Paragraph},
|
||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
use crate::config::colors::themes::Theme;
|
use crate::{
|
||||||
|
config::colors::themes::Theme,
|
||||||
|
state::pages::auth::AuthState
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Default)]
|
pub fn render_login(f: &mut Frame, area: Rect, theme: &Theme, state: &mut AuthState) {
|
||||||
pub struct LoginState {
|
let block = Block::default()
|
||||||
pub return_selected: bool,
|
.borders(Borders::ALL)
|
||||||
}
|
.border_type(BorderType::Rounded)
|
||||||
|
.border_style(Style::default().fg(theme.accent))
|
||||||
|
.style(Style::default().bg(theme.bg))
|
||||||
|
.title(" Login ");
|
||||||
|
|
||||||
impl LoginState {
|
let inner_area = block.inner(area);
|
||||||
pub fn render(&self, f: &mut Frame, area: Rect, theme: &Theme) {
|
f.render_widget(block, area);
|
||||||
let block = Block::default()
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.border_type(BorderType::Rounded)
|
|
||||||
.border_style(Style::default().fg(theme.accent))
|
|
||||||
.style(Style::default().bg(theme.bg))
|
|
||||||
.title(" Login ");
|
|
||||||
|
|
||||||
let inner_area = block.inner(area);
|
let chunks = Layout::default()
|
||||||
f.render_widget(block, area);
|
.direction(Direction::Vertical)
|
||||||
|
.constraints([
|
||||||
|
Constraint::Percentage(40),
|
||||||
|
Constraint::Length(3),
|
||||||
|
Constraint::Percentage(40),
|
||||||
|
])
|
||||||
|
.split(inner_area);
|
||||||
|
|
||||||
// Simple layout with return button
|
let button_style = if state.return_selected {
|
||||||
let chunks = Layout::default()
|
Style::default()
|
||||||
.direction(Direction::Vertical)
|
.fg(theme.highlight)
|
||||||
.constraints([
|
.add_modifier(ratatui::style::Modifier::BOLD)
|
||||||
Constraint::Percentage(40),
|
} else {
|
||||||
Constraint::Length(3),
|
Style::default().fg(theme.fg)
|
||||||
Constraint::Percentage(40),
|
};
|
||||||
])
|
|
||||||
.split(inner_area);
|
|
||||||
|
|
||||||
let button_style = if self.return_selected {
|
f.render_widget(
|
||||||
Style::default()
|
Paragraph::new("Return to Intro")
|
||||||
.fg(theme.highlight)
|
|
||||||
.add_modifier(ratatui::style::Modifier::BOLD)
|
|
||||||
} else {
|
|
||||||
Style::default().fg(theme.fg)
|
|
||||||
};
|
|
||||||
|
|
||||||
let button = Paragraph::new("Return to Intro")
|
|
||||||
.style(button_style)
|
.style(button_style)
|
||||||
.alignment(Alignment::Center)
|
.alignment(Alignment::Center)
|
||||||
.block(
|
.block(
|
||||||
Block::default()
|
Block::default()
|
||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
.border_type(BorderType::Plain)
|
.border_type(BorderType::Plain)
|
||||||
.border_style(if self.return_selected {
|
.border_style(if state.return_selected {
|
||||||
Style::default().fg(theme.accent)
|
Style::default().fg(theme.accent)
|
||||||
} else {
|
} else {
|
||||||
Style::default().fg(theme.border)
|
Style::default().fg(theme.border)
|
||||||
}),
|
}),
|
||||||
);
|
),
|
||||||
|
chunks[1]
|
||||||
f.render_widget(button, chunks[1]);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,64 +1,20 @@
|
|||||||
// src/state/pages/auth.rs
|
// src/state/pages/auth.rs
|
||||||
use ratatui::{
|
|
||||||
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
|
||||||
style::Style,
|
|
||||||
text::{Line, Span},
|
|
||||||
widgets::{Block, BorderType, Borders, Paragraph},
|
|
||||||
prelude::Widget,
|
|
||||||
Frame,
|
|
||||||
};
|
|
||||||
use crate::config::colors::themes::Theme;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct AuthState {
|
pub struct AuthState {
|
||||||
pub return_selected: bool,
|
pub return_selected: bool,
|
||||||
|
pub username: String,
|
||||||
|
pub password: String,
|
||||||
|
pub error_message: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AuthState {
|
impl AuthState {
|
||||||
pub fn render(&mut self, f: &mut Frame, area: Rect, theme: &Theme) {
|
pub fn new() -> Self {
|
||||||
let block = Block::default()
|
Self {
|
||||||
.borders(Borders::ALL)
|
return_selected: false,
|
||||||
.border_type(BorderType::Rounded)
|
username: String::new(),
|
||||||
.border_style(Style::default().fg(theme.accent))
|
password: String::new(),
|
||||||
.style(Style::default().bg(theme.bg))
|
error_message: None,
|
||||||
.title(" Authentication ");
|
}
|
||||||
|
|
||||||
let inner_area = block.inner(area);
|
|
||||||
f.render_widget(block, area);
|
|
||||||
|
|
||||||
let chunks = Layout::default()
|
|
||||||
.direction(Direction::Vertical)
|
|
||||||
.constraints([
|
|
||||||
Constraint::Percentage(40),
|
|
||||||
Constraint::Length(3),
|
|
||||||
Constraint::Percentage(40),
|
|
||||||
])
|
|
||||||
.split(inner_area);
|
|
||||||
|
|
||||||
// Return button
|
|
||||||
let button_style = if self.return_selected {
|
|
||||||
Style::default()
|
|
||||||
.fg(theme.highlight)
|
|
||||||
.add_modifier(ratatui::style::Modifier::BOLD)
|
|
||||||
} else {
|
|
||||||
Style::default().fg(theme.fg)
|
|
||||||
};
|
|
||||||
|
|
||||||
f.render_widget(
|
|
||||||
Paragraph::new("Return to Intro")
|
|
||||||
.style(button_style)
|
|
||||||
.alignment(Alignment::Center)
|
|
||||||
.block(
|
|
||||||
Block::default()
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.border_type(BorderType::Plain)
|
|
||||||
.border_style(if self.return_selected {
|
|
||||||
Style::default().fg(theme.accent)
|
|
||||||
} else {
|
|
||||||
Style::default().fg(theme.border)
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
chunks[1]
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use crate::components::{
|
|||||||
form::form::render_form,
|
form::form::render_form,
|
||||||
intro::{intro},
|
intro::{intro},
|
||||||
admin::{admin_panel::AdminPanelState},
|
admin::{admin_panel::AdminPanelState},
|
||||||
|
auth::login::render_login,
|
||||||
};
|
};
|
||||||
use crate::config::colors::themes::Theme;
|
use crate::config::colors::themes::Theme;
|
||||||
use ratatui::layout::{Constraint, Direction, Layout};
|
use ratatui::layout::{Constraint, Direction, Layout};
|
||||||
@@ -47,7 +48,7 @@ pub fn render_ui(
|
|||||||
// Use app_state's intro_state directly
|
// Use app_state's intro_state directly
|
||||||
app_state.ui.intro_state.render(f, main_content_area, theme);
|
app_state.ui.intro_state.render(f, main_content_area, theme);
|
||||||
}else if app_state.ui.show_login {
|
}else if app_state.ui.show_login {
|
||||||
auth_state.render(f, main_content_area, theme);
|
render_login(f, main_content_area, theme, auth_state);
|
||||||
} else if app_state.ui.show_admin {
|
} else if app_state.ui.show_admin {
|
||||||
// Create temporary AdminPanelState for rendering
|
// Create temporary AdminPanelState for rendering
|
||||||
let mut admin_state = AdminPanelState::new(
|
let mut admin_state = AdminPanelState::new(
|
||||||
|
|||||||
Reference in New Issue
Block a user