login logic in the components

This commit is contained in:
filipriec
2025-03-25 22:56:24 +01:00
parent 1fe139e0c5
commit aab11c1cba
3 changed files with 47 additions and 94 deletions

View File

@@ -1,64 +1,20 @@
// 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)]
pub struct AuthState {
pub return_selected: bool,
pub username: String,
pub password: String,
pub error_message: Option<String>,
}
impl AuthState {
pub fn render(&mut self, f: &mut Frame, area: Rect, theme: &Theme) {
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(" 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]
);
pub fn new() -> Self {
Self {
return_selected: false,
username: String::new(),
password: String::new(),
error_message: None,
}
}
}