pinakes-tui: add book management view and api key authentication
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I20f205d9e06a93a89e8f4433ed6f80576a6a6964
This commit is contained in:
parent
3d9f8933d2
commit
66861b8a20
18 changed files with 917 additions and 251 deletions
|
|
@ -10,14 +10,11 @@ use super::{format_date, format_duration, format_size, media_type_color};
|
|||
use crate::app::AppState;
|
||||
|
||||
pub fn render(f: &mut Frame, state: &AppState, area: Rect) {
|
||||
let item = match &state.selected_media {
|
||||
Some(item) => item,
|
||||
None => {
|
||||
let msg = Paragraph::new("No item selected")
|
||||
.block(Block::default().borders(Borders::ALL).title(" Detail "));
|
||||
f.render_widget(msg, area);
|
||||
return;
|
||||
},
|
||||
let Some(item) = &state.selected_media else {
|
||||
let msg = Paragraph::new("No item selected")
|
||||
.block(Block::default().borders(Borders::ALL).title(" Detail "));
|
||||
f.render_widget(msg, area);
|
||||
return;
|
||||
};
|
||||
|
||||
let chunks = Layout::default()
|
||||
|
|
@ -122,10 +119,7 @@ pub fn render(f: &mut Frame, state: &AppState, area: Rect) {
|
|||
Span::raw(pad),
|
||||
Span::styled(make_label("Year"), label_style),
|
||||
Span::styled(
|
||||
item
|
||||
.year
|
||||
.map(|y| y.to_string())
|
||||
.unwrap_or_else(|| "-".to_string()),
|
||||
item.year.map_or_else(|| "-".to_string(), |y| y.to_string()),
|
||||
value_style,
|
||||
),
|
||||
]));
|
||||
|
|
@ -136,8 +130,7 @@ pub fn render(f: &mut Frame, state: &AppState, area: Rect) {
|
|||
Span::styled(
|
||||
item
|
||||
.duration_secs
|
||||
.map(format_duration)
|
||||
.unwrap_or_else(|| "-".to_string()),
|
||||
.map_or_else(|| "-".to_string(), format_duration),
|
||||
value_style,
|
||||
),
|
||||
]));
|
||||
|
|
@ -194,6 +187,96 @@ pub fn render(f: &mut Frame, state: &AppState, area: Rect) {
|
|||
]));
|
||||
}
|
||||
|
||||
// Book metadata section
|
||||
if let Some(ref book) = state.book_metadata {
|
||||
lines.push(Line::default());
|
||||
lines.push(Line::from(Span::styled(
|
||||
"--- Book Metadata ---",
|
||||
Style::default()
|
||||
.fg(Color::Cyan)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)));
|
||||
if let Some(ref subtitle) = book.subtitle {
|
||||
lines.push(Line::from(vec![
|
||||
Span::raw(pad),
|
||||
Span::styled(make_label("Subtitle"), label_style),
|
||||
Span::styled(subtitle.as_str(), value_style),
|
||||
]));
|
||||
}
|
||||
if !book.authors.is_empty() {
|
||||
let authors: Vec<&str> =
|
||||
book.authors.iter().map(|a| a.name.as_str()).collect();
|
||||
lines.push(Line::from(vec![
|
||||
Span::raw(pad),
|
||||
Span::styled(make_label("Authors"), label_style),
|
||||
Span::styled(authors.join(", "), value_style),
|
||||
]));
|
||||
}
|
||||
if let Some(ref publisher) = book.publisher {
|
||||
lines.push(Line::from(vec![
|
||||
Span::raw(pad),
|
||||
Span::styled(make_label("Publisher"), label_style),
|
||||
Span::styled(publisher.as_str(), value_style),
|
||||
]));
|
||||
}
|
||||
if let Some(isbn) = book.isbn13.as_ref().or(book.isbn.as_ref()) {
|
||||
lines.push(Line::from(vec![
|
||||
Span::raw(pad),
|
||||
Span::styled(make_label("ISBN"), label_style),
|
||||
Span::styled(isbn.as_str(), value_style),
|
||||
]));
|
||||
}
|
||||
if let Some(ref language) = book.language {
|
||||
lines.push(Line::from(vec![
|
||||
Span::raw(pad),
|
||||
Span::styled(make_label("Language"), label_style),
|
||||
Span::styled(language.as_str(), value_style),
|
||||
]));
|
||||
}
|
||||
if let Some(pages) = book.page_count {
|
||||
lines.push(Line::from(vec![
|
||||
Span::raw(pad),
|
||||
Span::styled(make_label("Pages"), label_style),
|
||||
Span::styled(pages.to_string(), value_style),
|
||||
]));
|
||||
}
|
||||
if let Some(ref series) = book.series {
|
||||
let series_display = book
|
||||
.series_index
|
||||
.map_or_else(|| series.clone(), |idx| format!("{series} #{idx}"));
|
||||
lines.push(Line::from(vec![
|
||||
Span::raw(pad),
|
||||
Span::styled(make_label("Series"), label_style),
|
||||
Span::styled(series_display, value_style),
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
// Reading progress section
|
||||
if let Some(ref progress) = state.reading_progress {
|
||||
lines.push(Line::default());
|
||||
lines.push(Line::from(Span::styled(
|
||||
"--- Reading Progress ---",
|
||||
Style::default()
|
||||
.fg(Color::Cyan)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)));
|
||||
let page_display = progress.total_pages.map_or_else(
|
||||
|| format!("Page {}", progress.current_page),
|
||||
|total| format!("Page {} / {total}", progress.current_page),
|
||||
);
|
||||
lines.push(Line::from(vec![
|
||||
Span::raw(pad),
|
||||
Span::styled(make_label("Progress"), label_style),
|
||||
Span::styled(page_display, value_style),
|
||||
]));
|
||||
lines.push(Line::from(vec![
|
||||
Span::raw(pad),
|
||||
Span::styled(make_label("Status"), label_style),
|
||||
Span::styled(&progress.status, value_style),
|
||||
]));
|
||||
}
|
||||
|
||||
lines.push(Line::default());
|
||||
|
||||
// Section: Timestamps
|
||||
|
|
@ -216,11 +299,10 @@ pub fn render(f: &mut Frame, state: &AppState, area: Rect) {
|
|||
Span::styled(format_date(&item.updated_at), dim_style),
|
||||
]));
|
||||
|
||||
let title = if let Some(ref title_str) = item.title {
|
||||
format!(" Detail: {} ", title_str)
|
||||
} else {
|
||||
format!(" Detail: {} ", item.file_name)
|
||||
};
|
||||
let title = item.title.as_ref().map_or_else(
|
||||
|| format!(" Detail: {} ", item.file_name),
|
||||
|title_str| format!(" Detail: {title_str} "),
|
||||
);
|
||||
|
||||
let detail = Paragraph::new(lines)
|
||||
.block(Block::default().borders(Borders::ALL).title(title));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue