login logic in the components
This commit is contained in:
@@ -1,62 +1,58 @@
|
||||
// src/components/auth/login.rs
|
||||
|
||||
use ratatui::{
|
||||
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||
style::Style,
|
||||
text::{Line, Span},
|
||||
widgets::{Block, BorderType, Borders, Paragraph},
|
||||
Frame,
|
||||
};
|
||||
use crate::config::colors::themes::Theme;
|
||||
use crate::{
|
||||
config::colors::themes::Theme,
|
||||
state::pages::auth::AuthState
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct LoginState {
|
||||
pub return_selected: bool,
|
||||
}
|
||||
pub fn render_login(f: &mut Frame, area: Rect, theme: &Theme, state: &mut AuthState) {
|
||||
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 ");
|
||||
|
||||
impl LoginState {
|
||||
pub fn render(&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(" Login ");
|
||||
let inner_area = block.inner(area);
|
||||
f.render_widget(block, area);
|
||||
|
||||
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);
|
||||
|
||||
// Simple layout with return button
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([
|
||||
Constraint::Percentage(40),
|
||||
Constraint::Length(3),
|
||||
Constraint::Percentage(40),
|
||||
])
|
||||
.split(inner_area);
|
||||
let button_style = if state.return_selected {
|
||||
Style::default()
|
||||
.fg(theme.highlight)
|
||||
.add_modifier(ratatui::style::Modifier::BOLD)
|
||||
} else {
|
||||
Style::default().fg(theme.fg)
|
||||
};
|
||||
|
||||
let button_style = if self.return_selected {
|
||||
Style::default()
|
||||
.fg(theme.highlight)
|
||||
.add_modifier(ratatui::style::Modifier::BOLD)
|
||||
} else {
|
||||
Style::default().fg(theme.fg)
|
||||
};
|
||||
|
||||
let button = Paragraph::new("Return to Intro")
|
||||
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 {
|
||||
.border_style(if state.return_selected {
|
||||
Style::default().fg(theme.accent)
|
||||
} else {
|
||||
Style::default().fg(theme.border)
|
||||
}),
|
||||
);
|
||||
|
||||
f.render_widget(button, chunks[1]);
|
||||
}
|
||||
),
|
||||
chunks[1]
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user