Unset active account when adding additional accounts (#1258)

This commit is contained in:
Addison Beck 2022-01-24 07:28:39 -05:00 committed by GitHub
parent ef48ba1ae2
commit d211b3fcd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 18 deletions

View File

@ -5,15 +5,20 @@
#trigger="cdkOverlayOrigin" #trigger="cdkOverlayOrigin"
[hidden]="!showSwitcher" [hidden]="!showSwitcher"
> >
<app-avatar <ng-container *ngIf="activeAccountEmail != null; else noActiveAccount">
[data]="activeAccountEmail" <app-avatar
size="25" [data]="activeAccountEmail"
[circle]="true" size="25"
[fontSize]="14" [circle]="true"
[dynamic]="true" [fontSize]="14"
*ngIf="activeAccountEmail != null" [dynamic]="true"
></app-avatar> *ngIf="activeAccountEmail != null"
<span>{{ activeAccountEmail }}</span> ></app-avatar>
<span>{{ activeAccountEmail }}</span>
</ng-container>
<ng-template #noActiveAccount>
<span>{{ "switchAccount" | i18n }}</span>
</ng-template>
<i <i
class="fa" class="fa"
aria-hidden="true" aria-hidden="true"
@ -65,14 +70,16 @@
></i> ></i>
</a> </a>
</div> </div>
<div class="border" *ngIf="numberOfAccounts > 0"></div> <ng-container *ngIf="activeAccountEmail != null">
<ng-container *ngIf="numberOfAccounts < 4"> <div class="border" *ngIf="numberOfAccounts > 0"></div>
<a class="add" routerLink="/login" (click)="toggle()"> <ng-container *ngIf="numberOfAccounts < 4">
<i class="fa fa-plus" aria-hidden="true"></i> {{ "addAccount" | i18n }} <a class="add" routerLink="/login" (click)="addAccount()">
</a> <i class="fa fa-plus" aria-hidden="true"></i> {{ "addAccount" | i18n }}
</ng-container> </a>
<ng-container *ngIf="numberOfAccounts == 4"> </ng-container>
<a class="accountLimitReached">{{ "accountSwitcherLimitReached" | i18n }} </a> <ng-container *ngIf="numberOfAccounts == 4">
<span class="accountLimitReached">{{ "accountSwitcherLimitReached" | i18n }} </span>
</ng-container>
</ng-container> </ng-container>
</div> </div>
</ng-template> </ng-template>

View File

@ -65,7 +65,9 @@ export class AccountSwitcherComponent implements OnInit {
]; ];
get showSwitcher() { get showSwitcher() {
return !Utils.isNullOrWhitespace(this.activeAccountEmail); const userIsInAVault = !Utils.isNullOrWhitespace(this.activeAccountEmail);
const userIsAddingAnAdditionalAccount = Object.keys(this.accounts).length > 0;
return userIsInAVault || userIsAddingAnAdditionalAccount;
} }
get numberOfAccounts() { get numberOfAccounts() {
@ -111,6 +113,11 @@ export class AccountSwitcherComponent implements OnInit {
this.messagingService.send("switchAccount", { userId: userId }); this.messagingService.send("switchAccount", { userId: userId });
} }
async addAccount() {
this.toggle();
await this.stateService.setActiveUser(null);
}
private async createSwitcherAccounts(baseAccounts: { private async createSwitcherAccounts(baseAccounts: {
[userId: string]: Account; [userId: string]: Account;
}): Promise<{ [userId: string]: SwitcherAccount }> { }): Promise<{ [userId: string]: SwitcherAccount }> {

View File

@ -1807,5 +1807,8 @@
"example": "jdoe@example.com" "example": "jdoe@example.com"
} }
} }
},
"switchAccount": {
"message": "Switch Account"
} }
} }

View File

@ -176,7 +176,9 @@
} }
.accountLimitReached { .accountLimitReached {
display: block;
margin: 4px 0; margin: 4px 0;
padding: 5px 10px;
font-size: $font-size-small; font-size: $font-size-small;
} }
} }