use crate::api::Status;
use crate::ui::app::{App, TimelineType};
use crate::ui::content::ContentParser;
use crate::utils::format_time;
use crate::ui::image::ImageViewer;
use ratatui::{
layout::{Constraint, Direction, Layout, Rect},
style::{Color, Modifier, Style},
text::{Line, Span, Text},
widgets::{Block, Borders, List, ListItem, ListState, Paragraph, Wrap},
Frame,
};
pub fn render_timeline(f: &mut Frame, app: &App, area: Rect) {
let constraints: &[Constraint] = if app.error_message.is_some() {
&[Constraint::Length(3), Constraint::Min(0), Constraint::Length(3)]
} else {
&[Constraint::Length(3), Constraint::Min(0)]
};
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints(constraints)
.split(area);
render_header(f, app, chunks[0]);
render_status_list(f, app, chunks[1]);
if let Some(error) = &app.error_message {
let error_widget = Paragraph::new(error.clone())
.block(Block::default().borders(Borders::ALL).title("Debug/Error"))
.style(Style::default().fg(Color::Red))
.wrap(Wrap { trim: true });
f.render_widget(error_widget, chunks[2]);
}
}
fn render_header(f: &mut Frame, app: &App, area: Rect) {
let timeline_name = match app.timeline_type {
TimelineType::Home => "Home",
TimelineType::Local => "Local",
TimelineType::Federated => "Federated",
};
let header_text = if app.loading {
format!("{} Timeline (Loading...)", timeline_name)
} else {
format!("{} Timeline", timeline_name)
};
let header = Paragraph::new(header_text)
.block(Block::default().borders(Borders::ALL).title("Mastui"))
.style(Style::default().fg(Color::Cyan));
f.render_widget(header, area);
}
fn render_status_list(f: &mut Frame, app: &App, area: Rect) {
let statuses = &app.statuses;
if statuses.is_empty() && !app.loading {
let empty_msg = if let Some(error) = &app.error_message {
format!("Error: {}", error)
} else {
"No statuses to display".to_string()
};
let paragraph = Paragraph::new(empty_msg)
.block(Block::default().borders(Borders::ALL))
.wrap(Wrap { trim: true })
.style(Style::default().fg(Color::Yellow));
f.render_widget(paragraph, area);
return;
}
let items: Vec
", "\n")
.replace("
", "\n")
.replace("
", "\n")
.replace("