better resilience of account selection

This commit is contained in:
Nicolas Constant 2019-06-14 23:48:07 -04:00
parent b3ada67b11
commit 3c45a3de0b
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
1 changed files with 4 additions and 10 deletions

View File

@ -44,22 +44,16 @@ export class AccountsState {
@Action(SelectAccount) @Action(SelectAccount)
SelectAccount(ctx: StateContext<AccountsStateModel>, action: SelectAccount){ SelectAccount(ctx: StateContext<AccountsStateModel>, action: SelectAccount){
const state = ctx.getState(); const state = ctx.getState();
// const multiSelection = action.multiselection;
const selectedAccount = action.account; const selectedAccount = action.account;
// const copyAccounts = [...state.accounts];
// copyAccounts
// .filter(x => x.id !== selectedAccount.id)
// .forEach(x => x.isSelected = false);
const oldSelectedAccount = state.accounts.find(x => x.isSelected); const oldSelectedAccount = state.accounts.find(x => x.isSelected);
if(selectedAccount.id === oldSelectedAccount.id) return; if(oldSelectedAccount != null && selectedAccount.id === oldSelectedAccount.id) return;
const acc = state.accounts.find(x => x.id === selectedAccount.id); const acc = state.accounts.find(x => x.id === selectedAccount.id);
acc.isSelected = true; acc.isSelected = true;
oldSelectedAccount.isSelected = false;
if(oldSelectedAccount != null) oldSelectedAccount.isSelected = false;
ctx.patchState({ ctx.patchState({
accounts: [...state.accounts] accounts: [...state.accounts]