Add 'view' page for log
This commit is contained in:
parent
cae499f3ee
commit
3220ff50cb
4 changed files with 194 additions and 15 deletions
74
src/ui.rs
74
src/ui.rs
|
|
@ -7,7 +7,7 @@ use ratatui::{
|
|||
};
|
||||
|
||||
use crate::{
|
||||
app::{App, NewEntryMode, Screen},
|
||||
app::{App, LogViewPeriod, NewEntryMode, Screen},
|
||||
state::{AppState, TimeItem},
|
||||
};
|
||||
|
||||
|
|
@ -21,6 +21,7 @@ pub fn render(frame: &mut Frame, app: &App) {
|
|||
Screen::ConfigHelp => render_config_help(frame, app),
|
||||
Screen::NewEntry => render_new_entry(frame, app),
|
||||
Screen::ReassignProject => render_reassign_project(frame, app),
|
||||
Screen::LogView => render_log_view(frame, app),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -211,6 +212,7 @@ fn render_bottom_bar(frame: &mut Frame, area: Rect, app: &App) {
|
|||
("c", "config"),
|
||||
("n", "new"),
|
||||
("p", "project"),
|
||||
("v", "log"),
|
||||
("d", "delete"),
|
||||
("q", "quit"),
|
||||
];
|
||||
|
|
@ -314,6 +316,7 @@ fn render_help(frame: &mut Frame, _app: &App) {
|
|||
"Enter - Start/stop timer",
|
||||
"d - Delete task",
|
||||
"p - Reassign project",
|
||||
"v - View Watson log",
|
||||
"Ctrl+e - Edit tasks config",
|
||||
"c - Edit app config",
|
||||
"n - New task",
|
||||
|
|
@ -503,3 +506,72 @@ fn render_reassign_project(frame: &mut Frame, app: &App) {
|
|||
|
||||
frame.render_widget(help_text, chunks[1]);
|
||||
}
|
||||
|
||||
fn render_log_view(frame: &mut Frame, app: &App) {
|
||||
let area = frame.size();
|
||||
|
||||
// Create the main content area (leave space for command bar at bottom)
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([Constraint::Min(3), Constraint::Length(1)])
|
||||
.split(area);
|
||||
|
||||
let period_str = match app.log_view_period {
|
||||
LogViewPeriod::Day => "Day",
|
||||
LogViewPeriod::Week => "Week",
|
||||
LogViewPeriod::Month => "Month",
|
||||
};
|
||||
|
||||
let title = format!("Watson Log - {} View", period_str);
|
||||
|
||||
let block = Block::default()
|
||||
.title(title)
|
||||
.borders(Borders::ALL)
|
||||
.style(Style::default().fg(ACTIVE_COLOR).bg(Color::Reset));
|
||||
|
||||
// Calculate visible area for content
|
||||
let inner_area = block.inner(chunks[0]);
|
||||
let visible_lines = inner_area.height as usize;
|
||||
|
||||
// Get the visible slice of content
|
||||
let start = app.log_view_scroll;
|
||||
let end = (start + visible_lines).min(app.log_view_content.len());
|
||||
let visible_content: Vec<String> = app.log_view_content[start..end].to_vec();
|
||||
|
||||
let text = if visible_content.is_empty() {
|
||||
"No log entries for this period.".to_string()
|
||||
} else {
|
||||
visible_content.join("\n")
|
||||
};
|
||||
|
||||
let paragraph = Paragraph::new(text)
|
||||
.block(block)
|
||||
.style(Style::default().fg(Color::White))
|
||||
.wrap(ratatui::widgets::Wrap { trim: false });
|
||||
|
||||
frame.render_widget(paragraph, chunks[0]);
|
||||
|
||||
// Render command bar
|
||||
let commands = vec![
|
||||
("d", "day"),
|
||||
("w", "week"),
|
||||
("m", "month"),
|
||||
("j/k", "scroll"),
|
||||
("q/ESC", "back"),
|
||||
];
|
||||
|
||||
let command_text = format!(
|
||||
" {}",
|
||||
commands
|
||||
.iter()
|
||||
.map(|(key, desc)| format!("{} ({})", key, desc))
|
||||
.collect::<Vec<_>>()
|
||||
.join(" · ")
|
||||
);
|
||||
|
||||
let command_bar = Paragraph::new(command_text)
|
||||
.style(Style::default().fg(Color::White))
|
||||
.alignment(Alignment::Left);
|
||||
|
||||
frame.render_widget(command_bar, chunks[1]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue