From c7cf34d38f65da4f716d911ae8008ecf240f44e8 Mon Sep 17 00:00:00 2001 From: Conatum Date: Sat, 9 Sep 2023 14:24:52 +0300 Subject: [PATCH] fix(stats): Detect finished UI on submit. --- src/modules/statistics/ui/weeklymonthly.py | 16 ++++++++++------ src/utils/ui/leo.py | 10 ++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/modules/statistics/ui/weeklymonthly.py b/src/modules/statistics/ui/weeklymonthly.py index 54bd807d..fd295f82 100644 --- a/src/modules/statistics/ui/weeklymonthly.py +++ b/src/modules/statistics/ui/weeklymonthly.py @@ -483,12 +483,16 @@ class WeeklyMonthlyUI(StatsUI): ).with_connection(conn) if modified: - # If either goal type was modified, clear the rendered cache and refresh - for page_key, (goalf, statf) in self._card_cache.items(): - # If the stat period type is the same as the current period type - if page_key[2].period is self._stat_page.period: - self._card_cache[page_key] = (None, statf) - await self.refresh(thinking=interaction) + # Check whether the UI finished while we were interacting + if not self._stopped.done(): + # If either goal type was modified, clear the rendered cache and refresh + for page_key, (goalf, statf) in self._card_cache.items(): + # If the stat period type is the same as the current period type + if page_key[2].period is self._stat_page.period: + self._card_cache[page_key] = (None, statf) + await self.refresh(thinking=interaction) + else: + await interaction.delete_original_response() await press.response.send_modal(modal) async def edit_button_refresh(self): diff --git a/src/utils/ui/leo.py b/src/utils/ui/leo.py index 6d77e13d..aba4118c 100644 --- a/src/utils/ui/leo.py +++ b/src/utils/ui/leo.py @@ -48,6 +48,16 @@ class LeoUI(View): # TODO: Replace this with a substitutable ViewLayout class self._layout: Optional[tuple[tuple[Item, ...], ...]] = None + @property + def _stopped(self) -> asyncio.Future: + """ + Return an future indicating whether the View has finished interacting. + + Currently exposes a hidden attribute of the underlying View. + May be reimplemented in future. + """ + return self._View__stopped + def to_components(self) -> List[Dict[str, Any]]: """ Extending component generator to apply the set _layout, if it exists.