Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 37 additions & 37 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ pub struct AppImpl {
pub feeds: util::StatefulList<crate::rss::Feed>,
// entry stuff
pub current_entry_meta: Option<crate::rss::EntryMeta>,
pub entries: util::StatefulList<crate::rss::EntryMeta>,
pub entry_selection_position: usize,
pub current_entries: util::StatefulList<crate::rss::EntryMeta>,
pub current_entry_selection_position: usize,
pub current_entry_text: String,
pub entry_scroll_position: u16,
pub entry_lines_len: usize,
Expand Down Expand Up @@ -221,7 +221,7 @@ impl AppImpl {
should_quit: false,
error_flash: vec![],
feeds,
entries,
current_entries: entries,
selected,
entry_scroll_position: 0,
entry_lines_len: 0,
Expand All @@ -234,7 +234,7 @@ impl AppImpl {
mode: Mode::Normal,
read_mode: ReadMode::ShowUnread,
show_help: true,
entry_selection_position: 0,
current_entry_selection_position: 0,
flash: None,
event_s,
is_wsl,
Expand Down Expand Up @@ -273,7 +273,7 @@ impl AppImpl {
}

// Remove the entries from the feed in app state
self.entries.items.retain(|entry| entry.feed_id != feed_id);
self.current_entries.items.retain(|entry| entry.feed_id != feed_id);

// Update
self.update_current_feed_and_entries()?;
Expand Down Expand Up @@ -323,32 +323,32 @@ impl AppImpl {
vec![].into()
};

self.entries = entries;
self.current_entries = entries;

if self.entry_selection_position < self.entries.items.len() {
self.entries
if self.current_entry_selection_position < self.current_entries.items.len() {
self.current_entries
.state
.select(Some(self.entry_selection_position))
.select(Some(self.current_entry_selection_position))
} else {
match self.entries.items.len().checked_sub(1) {
Some(n) => self.entries.state.select(Some(n)),
None => self.entries.reset(),
match self.current_entries.items.len().checked_sub(1) {
Some(n) => self.current_entries.state.select(Some(n)),
None => self.current_entries.reset(),
}
}
Ok(())
}

fn update_entry_selection_position(&mut self) {
if self.entries.items.is_empty() {
self.entry_selection_position = 0
} else if self.entry_selection_position > self.entries.items.len() - 1 {
self.entry_selection_position = self.entries.items.len() - 1
if self.current_entries.items.is_empty() {
self.current_entry_selection_position = 0
} else if self.current_entry_selection_position > self.current_entries.items.len() - 1 {
self.current_entry_selection_position = self.current_entries.items.len() - 1
};
}

fn get_selected_entry(&self) -> Option<Result<crate::rss::EntryContent>> {
self.entries.state.selected().and_then(|selected_idx| {
self.entries
self.current_entries.state.selected().and_then(|selected_idx| {
self.current_entries
.items
.get(selected_idx)
.map(|item| item.id)
Expand All @@ -357,8 +357,8 @@ impl AppImpl {
}

fn get_selected_entry_meta(&self) -> Option<Result<crate::rss::EntryMeta>> {
self.entries.state.selected().and_then(|selected_idx| {
self.entries
self.current_entries.state.selected().and_then(|selected_idx| {
self.current_entries
.items
.get(selected_idx)
.map(|item| item.id)
Expand Down Expand Up @@ -403,7 +403,7 @@ impl AppImpl {
pub fn on_enter(&mut self) -> Result<()> {
match self.selected {
Selected::Entries | Selected::Entry(_) => {
if !self.entries.items.is_empty() {
if !self.current_entries.items.is_empty() {
if let Some(entry_meta) = &self.current_entry_meta {
if let Some(entry) = self.get_selected_entry() {
let entry = entry?;
Expand Down Expand Up @@ -529,21 +529,21 @@ impl AppImpl {
pub fn toggle_read_mode(&mut self) -> Result<()> {
match (&self.read_mode, &self.selected) {
(ReadMode::ShowRead, Selected::Feeds) | (ReadMode::ShowRead, Selected::Entries) => {
self.entry_selection_position = 0;
self.current_entry_selection_position = 0;
self.read_mode = ReadMode::ShowUnread
}
(ReadMode::ShowUnread, Selected::Feeds) | (ReadMode::ShowUnread, Selected::Entries) => {
self.entry_selection_position = 0;
self.current_entry_selection_position = 0;
self.read_mode = ReadMode::ShowRead
}
_ => (),
}
self.update_current_entries()?;

if !self.entries.items.is_empty() {
self.entries.reset();
if !self.current_entries.items.is_empty() {
self.current_entries.reset();
} else {
self.entries.unselect();
self.current_entries.unselect();
}

self.update_current_entry_meta()?;
Expand All @@ -558,9 +558,9 @@ impl AppImpl {
.as_ref()
.and_then(|feed| feed.link.as_deref().or(feed.feed_link.as_deref())),
Selected::Entries => self
.entries
.current_entries
.items
.get(self.entry_selection_position)
.get(self.current_entry_selection_position)
.and_then(|entry| entry.link.as_deref()),
Selected::Entry(e) => e.link.as_deref(),
Selected::None => None,
Expand Down Expand Up @@ -605,7 +605,7 @@ impl AppImpl {
match self.selected {
Selected::Feeds => (),
Selected::Entries => {
self.entry_selection_position = 0;
self.current_entry_selection_position = 0;
self.selected = Selected::Feeds
}
Selected::Entry(_) => {
Expand All @@ -628,9 +628,9 @@ impl AppImpl {
self.update_current_feed_and_entries()?;
}
Selected::Entries => {
if !self.entries.items.is_empty() {
self.entries.previous();
self.entry_selection_position = self.entries.state.selected().unwrap();
if !self.current_entries.items.is_empty() {
self.current_entries.previous();
self.current_entry_selection_position = self.current_entries.state.selected().unwrap();
self.update_current_entry_meta()?;
}
}
Expand All @@ -648,9 +648,9 @@ impl AppImpl {
pub fn on_right(&mut self) -> Result<()> {
match self.selected {
Selected::Feeds => {
if !self.entries.items.is_empty() {
if !self.current_entries.items.is_empty() {
self.selected = Selected::Entries;
self.entries.reset();
self.current_entries.reset();
self.update_current_entry_meta()?;
}
Ok(())
Expand All @@ -668,9 +668,9 @@ impl AppImpl {
self.update_current_feed_and_entries()?;
}
Selected::Entries => {
if !self.entries.items.is_empty() {
self.entries.next();
self.entry_selection_position = self.entries.state.selected().unwrap();
if !self.current_entries.items.is_empty() {
self.current_entries.next();
self.current_entry_selection_position = self.current_entries.state.selected().unwrap();
self.update_current_entry_meta()?;
}
}
Expand Down
24 changes: 15 additions & 9 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ where
text.push('\n');
}

if let Some(item) = app.entries.items.get(0) {
if let Some(item) = app.current_entries.items.get(0) {
if let Some(pub_date) = &item.pub_date {
text.push_str("Most recent entry at: ");
text.push_str(pub_date.to_string().as_str());
Expand All @@ -254,7 +254,7 @@ where
ReadMode::ShowRead => text.push_str("Read entries: "),
ReadMode::All => unreachable!("ReadMode::All should never be possible from the UI!"),
}
text.push_str(app.entries.items.len().to_string().as_str());
text.push_str(app.current_entries.items.len().to_string().as_str());
text.push('\n');

if let Some(feed_kind) = app.current_feed.as_ref().map(|feed| feed.feed_kind) {
Expand Down Expand Up @@ -331,7 +331,7 @@ where
B: Backend,
{
let entries = app
.entries
.current_entries
.items
.iter()
.map(|entry| {
Expand All @@ -342,13 +342,19 @@ where
})
.collect::<Vec<ListItem>>();

let default_title = "Entries".to_string();

let title = app
let default_feed_title = "Entries".to_string();
let feed_title = app
.current_feed
.as_ref()
.and_then(|feed| feed.title.as_ref())
.unwrap_or(&default_title);
.unwrap_or(&default_feed_title);

let read_mode_suff = match app.read_mode {
ReadMode::All => " (all)",
ReadMode::ShowRead => " (read)",
ReadMode::ShowUnread => " (unread)",
};
let title = format!("{}{}", feed_title, read_mode_suff);

let entries_titles = List::new(entries).block(
Block::default().borders(Borders::ALL).title(Span::styled(
Expand Down Expand Up @@ -386,11 +392,11 @@ where
.wrap(Wrap { trim: false })
.scroll((0, 0));

f.render_stateful_widget(entries_titles, chunks[0], &mut app.entries.state);
f.render_stateful_widget(entries_titles, chunks[0], &mut app.current_entries.state);
f.render_widget(error_widget, chunks[1]);
}
} else {
f.render_stateful_widget(entries_titles, area, &mut app.entries.state);
f.render_stateful_widget(entries_titles, area, &mut app.current_entries.state);
}
}

Expand Down