Skip to content

feat: added a confirmation step during app reset #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2023
Merged
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
7 changes: 5 additions & 2 deletions app/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,8 @@ def __init__(
dialog_controller: Callable[[any, utils.AlertDialogControls], None],
title: str,
description: str,
data_on_confirmed: any,
on_proceed: Callable,
data_on_confirmed: Optional[any] = None,
on_cancel: Optional[Callable] = None,
proceed_button_label: str = "Proceed",
cancel_button_label: str = "Cancel",
Expand Down Expand Up @@ -648,7 +648,10 @@ def on_cancel_btn_clicked(self, e):

def on_proceed_btn_clicked(self, e):
self.close_dialog()
self.on_proceed_callback(self.data_on_confirmed)
if self.data_on_confirmed is not None:
self.on_proceed_callback(self.data_on_confirmed)
else:
self.on_proceed_callback()


class TPopUpMenuItem(PopupMenuItem):
Expand Down
23 changes: 21 additions & 2 deletions app/preferences/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def __init__(
self.on_reset_app_callback = on_reset_app_callback
self.preferences: Optional[Preferences] = None
self.currencies = []
self.pop_up_handler = None

def set_available_currencies(self):
self.currencies = [
Expand Down Expand Up @@ -107,7 +108,25 @@ def on_language_selected(self, e):
return
self.preferences.language = e.control.value

def on_reset_app(self, e):
def on_reset_app_clicked(self, e):
"""Ask user to confirm this action"""
if self.pop_up_handler:
# Close any existing dialog
self.pop_up_handler.close_dialog()
# Add a confirmation dialog
self.pop_up_handler = views.ConfirmDisplayPopUp(
dialog_controller=self.dialog_controller,
title="Are You Sure?",
description=f"Are you sure you wish to reset the app?\nThis will clear all your data.",
on_proceed=self.on_reset_app_confirmed,
proceed_button_label="Yes! Reset",
)
self.pop_up_handler.open_dialog()

def on_reset_app_confirmed(
self,
):
"""Reset the app to default state"""
logger.warning("Resetting the app to default state")
logger.warning("Clearning preferences")
result: IntentResult[None] = self.intent.clear_preferences()
Expand Down Expand Up @@ -189,7 +208,7 @@ def build(self):
self.reset_button = views.TDangerButton(
label="Reset App and Quit",
icon=icons.RESTART_ALT_OUTLINED,
on_click=self.on_reset_app,
on_click=self.on_reset_app_clicked,
tooltip="Warning: This will reset the app to default state and delete all data. You will have to restart the app.",
)

Expand Down