Edit and delete entries from view page

This commit is contained in:
Ian Keane 2025-11-22 11:27:01 -05:00
parent 3220ff50cb
commit 605d5f5792
5 changed files with 229 additions and 33 deletions

View file

@ -316,7 +316,7 @@ fn render_help(frame: &mut Frame, _app: &App) {
"Enter - Start/stop timer",
"d - Delete task",
"p - Reassign project",
"v - View Watson log",
"v - View Watson log (e to edit entries, x to delete)",
"Ctrl+e - Edit tasks config",
"c - Edit app config",
"n - New task",
@ -527,36 +527,50 @@ fn render_log_view(frame: &mut Frame, app: &App) {
let block = Block::default()
.title(title)
.borders(Borders::ALL)
.style(Style::default().fg(ACTIVE_COLOR).bg(Color::Reset));
.style(Style::default().fg(ACTIVE_COLOR));
// Calculate visible area for content
let inner_area = block.inner(chunks[0]);
let visible_lines = inner_area.height as usize;
// Build list items with selection highlighting
let items: Vec<ListItem> = app
.log_view_content
.iter()
.enumerate()
.map(|(idx, line)| {
// Check if this is a frame line (starts with tab) and matches selected frame
let is_selected = if line.starts_with('\t') {
// Count how many frame lines we've seen so far
let frame_idx = app.log_view_content[..=idx]
.iter()
.filter(|l| l.starts_with('\t'))
.count()
.saturating_sub(1);
frame_idx == app.log_view_selected
} else {
false
};
// 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 style = if is_selected {
Style::default()
.fg(ACTIVE_COLOR)
.add_modifier(Modifier::REVERSED)
} else {
Style::default().fg(Color::White)
};
let text = if visible_content.is_empty() {
"No log entries for this period.".to_string()
} else {
visible_content.join("\n")
};
ListItem::new(Line::from(vec![Span::styled(line.clone(), style)]))
})
.collect();
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]);
let list = List::new(items).block(block);
frame.render_widget(list, chunks[0]);
// Render command bar
let commands = vec![
("d", "day"),
("w", "week"),
("m", "month"),
("j/k", "scroll"),
("j/k", "select"),
("e", "edit"),
("x", "delete"),
("q/ESC", "back"),
];