Skip to content

Commit

Permalink
feat(term): show annotations in feed detail
Browse files Browse the repository at this point in the history
  • Loading branch information
ymgyt committed Apr 13, 2024
1 parent b25a147 commit cb0db4a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
23 changes: 18 additions & 5 deletions crates/synd_term/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ use schemars::JsonSchema;
use serde::Serialize;
use synd_feed::types::{Category, FeedType, Requirement};

use crate::client::{
mutation,
query::{self},
use crate::{
client::{
mutation,
query::{self},
},
ui,
};

mod time;
Expand Down Expand Up @@ -97,8 +100,18 @@ pub struct Feed {
pub generator: Option<String>,
pub entries: Vec<EntryMeta>,
pub authors: Vec<String>,
pub requirement: Option<Requirement>,
pub category: Option<Category<'static>>,
requirement: Option<Requirement>,
category: Option<Category<'static>>,
}

impl Feed {
pub fn requirement(&self) -> Requirement {
self.requirement.unwrap_or(ui::DEFAULT_REQUIREMNET)
}

pub fn category(&self) -> &Category<'static> {
self.category.as_ref().unwrap_or(ui::default_category())
}
}

impl From<query::subscription::Feed> for Feed {
Expand Down
24 changes: 17 additions & 7 deletions crates/synd_term/src/ui/components/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,10 @@ impl Subscription {
.unwrap_or(ui::UNKNOWN_SYMBOL);
let desc = feed_meta.description.as_deref().unwrap_or("");
let requirement = feed_meta
.requirement
.unwrap_or(ui::DEFAULT_REQUIREMNET)
.requirement()
.label(cx.theme.requiment_fg)
.to_vec();
let category = feed_meta
.category
.as_ref()
.unwrap_or_else(|| ui::default_category());
let category = feed_meta.category();
// TODO: fallback icon
let icon = cx.categories.icon(category).unwrap();

Expand Down Expand Up @@ -234,7 +230,7 @@ impl Subscription {
return;
};

let vertical = Layout::vertical([Constraint::Length(2), Constraint::Min(0)]);
let vertical = Layout::vertical([Constraint::Length(3), Constraint::Min(0)]);
let [meta_area, entries_area] = vertical.areas(inner);
let entries_area = entries_area.inner(&Margin {
vertical: 1,
Expand Down Expand Up @@ -283,6 +279,20 @@ impl Subscription {
}),
])),
]),
Row::new([
Cell::new(Span::styled(
" Category",
Style::default().add_modifier(Modifier::BOLD),
)),
Cell::new(Span::from(feed.category().as_str())),
Cell::new(Line::from(vec![
Span::styled(
" Requirement ",
Style::default().add_modifier(Modifier::BOLD),
),
Span::from(feed.requirement().to_string()),
])),
]),
];

let table = Table::new(meta_rows, widths)
Expand Down

0 comments on commit cb0db4a

Please sign in to comment.