keep account selection in state management
This commit is contained in:
parent
1c16425bb0
commit
f9eaeb8904
|
@ -6,11 +6,15 @@ export class AddAccount {
|
|||
constructor(public account: AccountInfo) {}
|
||||
}
|
||||
|
||||
export class SelectAccount {
|
||||
static readonly type = '[Accounts] Select account';
|
||||
constructor(public account: AccountInfo, public multiselection: boolean = false) {}
|
||||
}
|
||||
|
||||
export interface AccountsStateModel {
|
||||
accounts: AccountInfo[];
|
||||
}
|
||||
|
||||
|
||||
@State<AccountsStateModel>({
|
||||
name: 'registeredaccounts',
|
||||
defaults: {
|
||||
|
@ -25,10 +29,28 @@ export class AccountsState {
|
|||
accounts: [...state.accounts, action.account]
|
||||
});
|
||||
}
|
||||
|
||||
@Action(SelectAccount)
|
||||
SelectAccount(ctx: StateContext<AccountsStateModel>, action: SelectAccount){
|
||||
const state = ctx.getState();
|
||||
const multiSelection = action.multiselection;
|
||||
const selectedAccount = action.account;
|
||||
const accounts = [...state.accounts];
|
||||
if(!multiSelection) {
|
||||
accounts.forEach(x => x.isSelected = false);
|
||||
}
|
||||
const acc = accounts.find(x => x.username === selectedAccount.username && x.instance === selectedAccount.instance);
|
||||
acc.isSelected = !acc.isSelected;
|
||||
|
||||
ctx.patchState({
|
||||
accounts: accounts
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class AccountInfo {
|
||||
username: string;
|
||||
instance: string;
|
||||
token: TokenData;
|
||||
isSelected: boolean;
|
||||
}
|
Loading…
Reference in New Issue