Close to the ui final version

This commit is contained in:
Marco De Araujo 2025-12-24 14:47:57 -04:00
parent d614ec4d18
commit b130c4550d
9 changed files with 46 additions and 69 deletions

View file

@ -16,7 +16,7 @@ use ratatui::{
layout::{Alignment, Constraint, Direction, Layout, Rect},
style::{Color, Modifier, Style},
text::{Line, Span, Text},
widgets::{Block, Borders, TableState, Padding, Paragraph},
widgets::{Block, Borders, Padding, Paragraph},
};
use std::{
@ -32,7 +32,6 @@ pub struct App {
update_interval: Duration,
endpoints: UptimeKumaEndpoints,
client: UptimeKumaClient,
list_state: TableState,
}
impl App {
@ -102,21 +101,7 @@ impl App {
frame.render_widget(no_data, area);
}
fn move_selection(&mut self, direction: isize) {
if self.state.monitors.is_empty() {
return;
}
let current = self.list_state.selected().unwrap_or(0);
let new_index = (current as isize + direction) as usize;
let new_index = new_index.clamp(0, self.state.monitors.len() - 1);
self.list_state.select(Some(new_index));
self.state.selected_index = new_index;
}
fn render(&mut self) {
let mut list_state = self.list_state.clone();
let _ = self.terminal.draw(|frame| {
let area = frame.area();
let chunks = Layout::default()
@ -134,7 +119,7 @@ impl App {
} else if self.state.monitors.is_empty() {
Self::render_no_data(frame, chunks[1]);
} else {
render_monitor_list(frame, chunks[1], &self.state, &mut list_state);
render_monitor_list(frame, chunks[1], &self.state);
}
});
}
@ -148,8 +133,6 @@ impl App {
match key.code {
KeyCode::Char('q') | KeyCode::Esc => self.should_quit = true,
KeyCode::Up => self.move_selection(-1),
KeyCode::Down => self.move_selection(1),
_ => {}
}
}
@ -185,8 +168,6 @@ impl App {
terminal.hide_cursor()?;
let state = DashboardViewState::new();
let mut list_state = TableState::default();
list_state.select(Some(0));
Ok(Self {
state,
@ -196,7 +177,6 @@ impl App {
update_interval: Duration::from_secs(30),
endpoints,
client: UptimeKumaClient::new(),
list_state: list_state,
})
}