Skip to content

Commit

Permalink
feat(term): show entry detail
Browse files Browse the repository at this point in the history
  • Loading branch information
ymgyt committed May 29, 2024
1 parent b2fa928 commit e9162af
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 11 deletions.
5 changes: 5 additions & 0 deletions crates/synd_term/src/types/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ pub type Time = synd_feed::types::Time;

pub trait TimeExt {
fn local_ymd(&self) -> String;
fn local_ymd_hm(&self) -> String;
}

impl TimeExt for Time {
fn local_ymd(&self) -> String {
self.naive_local().format("%Y-%m-%d").to_string()
}

fn local_ymd_hm(&self) -> String {
self.naive_local().format("%Y-%m-%d %H:%M").to_string()
}
}
56 changes: 51 additions & 5 deletions crates/synd_term/src/ui/components/entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl Entries {
let [entries_area, summary_area] = vertical.areas(area);

self.render_entries(entries_area, buf, cx);
self.render_summary(summary_area, buf, cx);
self.render_detail(summary_area, buf, cx);
}

fn render_entries(&self, area: Rect, buf: &mut Buffer, cx: &Context<'_>) {
Expand Down Expand Up @@ -183,7 +183,7 @@ impl Entries {
}
};
let header = Row::new([
Cell::from(" Published"),
Cell::from(concat!(icon!(calendar), " Published")),
Cell::from(format!("󰯂 Entry {n}/{m}")),
Cell::from("󰑫 Feed"),
Cell::from(concat!(icon!(requirement), " Req")),
Expand Down Expand Up @@ -237,7 +237,7 @@ impl Entries {
)
}

fn render_summary(&self, area: Rect, buf: &mut Buffer, cx: &Context<'_>) {
fn render_detail(&self, area: Rect, buf: &mut Buffer, cx: &Context<'_>) {
let block = Block::new()
.padding(Padding::horizontal(2))
.borders(Borders::TOP)
Expand All @@ -249,15 +249,61 @@ impl Entries {
let Some(entry) = self.selected_entry() else {
return;
};

let vertical = Layout::vertical([
Constraint::Length(1),
Constraint::Length(1),
Constraint::Length(1),
Constraint::Length(1),
Constraint::Length(1),
Constraint::Min(0),
]);
let [title_area, url_area, published_area, _, summary_heading_area, summary_area] =
vertical.areas(inner);

Line::from(vec![
Span::from(concat!(icon!(entry), " Entry")).bold(),
Span::from(" "),
Span::from(entry.title.as_deref().unwrap_or(ui::UNKNOWN_SYMBOL)),
])
.render(title_area, buf);

Line::from(vec![
Span::from(concat!(icon!(open), " URL")).bold(),
Span::from(" "),
Span::from(entry.website_url.as_deref().unwrap_or_default()),
])
.render(url_area, buf);

Line::from(vec![
Span::from(concat!(icon!(calendar), " Published")).bold(),
Span::from(" "),
Span::from(
entry
.published
.as_ref()
.or(entry.updated.as_ref())
.map_or_else(|| ui::UNKNOWN_SYMBOL.to_string(), TimeExt::local_ymd_hm),
),
])
.render(published_area, buf);

let Some(summary) = entry.summary_text(inner.width.into()) else {
return;
};
// should to Lines?

Line::from(
Span::from(concat!(icon!(summary), " Summary"))
.bold()
.underlined(),
)
.render(summary_heading_area, buf);

let paragraph = Paragraph::new(Text::from(summary))
.wrap(Wrap { trim: false })
.style(cx.theme.entries.summary)
.alignment(Alignment::Left);

Widget::render(paragraph, inner, buf);
Widget::render(paragraph, summary_area, buf);
}
}
2 changes: 1 addition & 1 deletion crates/synd_term/src/ui/components/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl StatusLine {
let per_screen_keys = match tab {
Some(Tab::Feeds) => pre_keys
.iter()
.chain(&[("Ent", "󰏌"), ("a", "󰑫"), ("e", ""), ("d", "󰼡")])
.chain(&[("Ent", icon!(open)), ("a", "󰑫"), ("e", ""), ("d", "󰼡")])
.chain(suf_keys),
Some(Tab::Entries) => pre_keys.iter().chain(&[("Ent", "󰏌")]).chain(suf_keys),
// Imply login
Expand Down
10 changes: 5 additions & 5 deletions crates/synd_term/src/ui/components/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
self,
components::filter::{FeedFilter, FilterResult},
extension::RectExt,
Context,
icon, Context,
},
};

Expand Down Expand Up @@ -249,7 +249,7 @@ impl Subscription {
let header = Row::new([
Cell::from(" Updated"),
Cell::from(format!("󰑫 Feed {n}/{m}")),
Cell::from(" URL"),
Cell::from(concat!(icon!(open), " URL")),
Cell::from("󰎞 Description"),
Cell::from(" Req"),
]);
Expand Down Expand Up @@ -415,9 +415,9 @@ impl Subscription {
};

let header = Row::new([
Cell::new(Span::from(" Published")),
Cell::new(Span::from("󰯂 Entry")),
Cell::new(Span::from("󱙓 Summary")),
Cell::new(Span::from(concat!(icon!(calendar), " Published"))),
Cell::new(Span::from(concat!(icon!(entry), " Entry"))),
Cell::new(Span::from(concat!(icon!(summary), " Summary"))),
]);

let rows = feed.entries.iter().map(entry);
Expand Down
12 changes: 12 additions & 0 deletions crates/synd_term/src/ui/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,27 @@ macro_rules! icon {
(category) => {
""
};
(calendar) => {
""
};
(entry) => {
"󰯂"
};
(filter) => {
"󰈶"
};
(requirement) => {
""
};
(open) => {
"󰏌"
};
(search) => {
""
};
(summary) => {
"󱙓"
};
}

pub(crate) use icon;

0 comments on commit e9162af

Please sign in to comment.