Skip to content
Snippets Groups Projects

Automatically add accounts to a known list after performing the appropriate actions

Merged Jakub Ziebinski requested to merge jziebinski/known-accounts into develop
All threads resolved!
1 file
+ 2
12
Compare changes
  • Side-by-side
  • Inline
@@ -43,10 +43,6 @@ class SetAccount(BaseScreen, FormScreen[Profile]):
yield self._account_name_input
yield self._working_account_checkbox
def on_mount(self) -> None:
# TODO: probably no need for this method after https://gitlab.syncad.com/hive/clive/-/issues/238
self.context.accounts.known.clear()
async def apply_and_validate(self) -> None:
try:
account_name = self._account_name_input.value_or_error
@@ -62,20 +58,14 @@ class SetAccount(BaseScreen, FormScreen[Profile]):
# allow only for adding one account
self.context.accounts.watched.clear()
self.context.accounts.known.clear()
self.context.accounts.unset_working_account()
self._remove_invalid_known_accounts(account_name)
self.context.accounts.known.add(account_name)
if self.__is_working_account():
self.context.accounts.set_working_account(account_name)
else:
self.context.accounts.watched.add(account_name)
def _remove_invalid_known_accounts(self, account_name_to_keep: str) -> None:
"""Remove all known accounts except the one that should be kept."""
# TODO: probably no need for this method after https://gitlab.syncad.com/hive/clive/-/issues/238
for known_account in self.context.accounts.known:
if known_account.name != account_name_to_keep:
self.context.accounts.known.remove(known_account)
def __is_working_account(self) -> bool:
return self.query_one(WorkingAccountCheckbox).value
Loading