Skip to main content

tui/app/
paging.rs

1//! The Transactions tab's server pages: a reply, a page turn and the continuation at an edge.
2
3use crate::app::App;
4use crate::tabs::fetch::Fetch;
5use crate::tabs::list::ListTab;
6use crate::view::Tab;
7use crate::window::WindowId;
8
9impl App {
10    pub(super) fn deliver_transactions_reply(&mut self, window: WindowId, wire: &str) {
11        let Some(list) = self.win_mut::<ListTab>(window) else {
12            return;
13        };
14        list.on_reply(wire);
15        let idle = list.state == Fetch::Idle;
16        if idle {
17            self.ensure_list_loaded(window);
18        }
19    }
20
21    /// Fetch the next or previous page of the Transactions tab.
22    pub fn page_transactions(&mut self, forward: bool) {
23        if let Some(window) = self.front_or_say(Tab::Transactions) {
24            self.load_page(window, forward, false);
25        }
26    }
27
28    /// Continue window `window` into the next (`forward`) or previous page when its selection
29    /// is on the loaded page's edge row; `false` when the move stays on the page.
30    pub fn continue_transactions_page(&mut self, window: WindowId, forward: bool) -> bool {
31        self.load_page(window, forward, true)
32    }
33
34    fn load_page(&mut self, window: WindowId, forward: bool, from_edge: bool) -> bool {
35        let Some(list) = self.win_mut::<ListTab>(window) else {
36            return false;
37        };
38        let turned = if from_edge {
39            list.turn_page_at_edge(forward)
40        } else {
41            list.turn_page(forward)
42        };
43        if turned {
44            self.load_window(window);
45        }
46        turned
47    }
48}