Add processing state to next page load

This commit is contained in:
edouardparis 2024-09-23 11:58:46 +02:00
parent 1a370d3806
commit 0219752f78
4 changed files with 37 additions and 8 deletions

View File

@ -75,6 +75,7 @@ pub struct Home {
pending_events: Vec<HistoryTransaction>,
events: Vec<HistoryTransaction>,
is_last_page: bool,
processing: bool,
selected_event: Option<(usize, usize)>,
labels_edited: LabelsEdited,
warning: Option<Error>,
@ -106,6 +107,7 @@ impl Home {
labels_edited: LabelsEdited::default(),
warning: None,
is_last_page: false,
processing: false,
}
}
}
@ -138,6 +140,7 @@ impl State for Home {
&self.pending_events,
&self.events,
self.is_last_page,
self.processing,
),
)
}
@ -196,6 +199,7 @@ impl State for Home {
Message::HistoryTransactionsExtension(res) => match res {
Err(e) => self.warning = Some(e),
Ok(events) => {
self.processing = false;
self.warning = None;
self.is_last_page = (events.len() as u64) < HISTORY_EVENT_PAGE_SIZE;
for event in events {
@ -243,6 +247,7 @@ impl State for Home {
if let Some(last) = self.events.last() {
let daemon = daemon.clone();
let last_event_date = last.time.unwrap();
self.processing = true;
return Command::perform(
async move {
let mut limit = HISTORY_EVENT_PAGE_SIZE;

View File

@ -44,6 +44,7 @@ pub struct TransactionsPanel {
warning: Option<Error>,
create_rbf_modal: Option<CreateRbfModal>,
is_last_page: bool,
processing: bool,
}
impl TransactionsPanel {
@ -57,6 +58,7 @@ impl TransactionsPanel {
warning: None,
create_rbf_modal: None,
is_last_page: false,
processing: false,
}
}
@ -88,6 +90,7 @@ impl State for TransactionsPanel {
&self.txs,
self.warning.as_ref(),
self.is_last_page,
self.processing,
)
}
}
@ -111,6 +114,7 @@ impl State for TransactionsPanel {
Message::HistoryTransactionsExtension(res) => match res {
Err(e) => self.warning = Some(e),
Ok(txs) => {
self.processing = false;
self.warning = None;
self.is_last_page = (txs.len() as u64) < HISTORY_EVENT_PAGE_SIZE;
for tx in txs {
@ -217,6 +221,7 @@ impl State for TransactionsPanel {
if let Some(last) = self.txs.last() {
let daemon = daemon.clone();
let last_tx_date = last.time.unwrap();
self.processing = true;
return Command::perform(
async move {
let mut limit = HISTORY_EVENT_PAGE_SIZE;

View File

@ -21,6 +21,7 @@ use crate::{
daemon::model::{HistoryTransaction, TransactionKind},
};
#[allow(clippy::too_many_arguments)]
pub fn home_view<'a>(
balance: &'a bitcoin::Amount,
unconfirmed_balance: &'a bitcoin::Amount,
@ -29,6 +30,7 @@ pub fn home_view<'a>(
pending_events: &'a [HistoryTransaction],
events: &'a [HistoryTransaction],
is_last_page: bool,
processing: bool,
) -> Element<'a, Message> {
Column::new()
.push(h3("Balance"))
@ -122,14 +124,22 @@ pub fn home_view<'a>(
Some(
Container::new(
Button::new(
text("See more")
.width(Length::Fill)
.horizontal_alignment(alignment::Horizontal::Center),
text(if processing {
"Fetching ..."
} else {
"See more"
})
.width(Length::Fill)
.horizontal_alignment(alignment::Horizontal::Center),
)
.width(Length::Fill)
.padding(15)
.style(theme::Button::TransparentBorder)
.on_press(Message::Next),
.on_press_maybe(if !processing {
Some(Message::Next)
} else {
None
}),
)
.width(Length::Fill)
.style(theme::Container::Card(theme::Card::Simple)),

View File

@ -26,6 +26,7 @@ pub fn transactions_view<'a>(
txs: &'a [HistoryTransaction],
warning: Option<&'a Error>,
is_last_page: bool,
processing: bool,
) -> Element<'a, Message> {
dashboard(
&Menu::Transactions,
@ -59,14 +60,22 @@ pub fn transactions_view<'a>(
Some(
Container::new(
Button::new(
text("See more")
.width(Length::Fill)
.horizontal_alignment(alignment::Horizontal::Center),
text(if processing {
"Fetching ..."
} else {
"See more"
})
.width(Length::Fill)
.horizontal_alignment(alignment::Horizontal::Center),
)
.width(Length::Fill)
.padding(15)
.style(theme::Button::TransparentBorder)
.on_press(Message::Next),
.on_press_maybe(if !processing {
Some(Message::Next)
} else {
None
}),
)
.width(Length::Fill)
.style(theme::Container::Card(theme::Card::Simple)),