1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-24 04:04:24 +00:00

[PM-21060] Refactor Has Nudges Service (#14653)

* refactor has nudges service to be its own Observable inside the vault nudges service.
This commit is contained in:
Jason Ng
2025-05-07 13:12:46 -04:00
committed by GitHub
parent cbe1c378ec
commit daaf81ec36
5 changed files with 107 additions and 93 deletions

View File

@@ -1,53 +1,70 @@
import { Component } from "@angular/core";
import { combineLatest, map } from "rxjs";
import { Component, OnInit } from "@angular/core";
import { combineLatest, firstValueFrom, map, Observable } from "rxjs";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { getUserId } from "@bitwarden/common/auth/services/account.service";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { HasNudgeService } from "@bitwarden/vault";
import { UserId } from "@bitwarden/common/types/guid";
import { VaultNudgesService } from "@bitwarden/vault";
@Component({
selector: "app-tabs-v2",
templateUrl: "./tabs-v2.component.html",
providers: [HasNudgeService],
})
export class TabsV2Component {
export class TabsV2Component implements OnInit {
private activeUserId: UserId | null = null;
protected navButtons$: Observable<
{
label: string;
page: string;
iconKey: string;
iconKeyActive: string;
showBerry?: boolean;
}[]
> = new Observable();
constructor(
private readonly hasNudgeService: HasNudgeService,
private vaultNudgesService: VaultNudgesService,
private accountService: AccountService,
private readonly configService: ConfigService,
) {}
protected navButtons$ = combineLatest([
this.configService.getFeatureFlag$(FeatureFlag.PM8851_BrowserOnboardingNudge),
this.hasNudgeService.nudgeStatus$(),
]).pipe(
map(([onboardingFeatureEnabled, nudgeStatus]) => {
return [
{
label: "vault",
page: "/tabs/vault",
iconKey: "lock",
iconKeyActive: "lock-f",
},
{
label: "generator",
page: "/tabs/generator",
iconKey: "generate",
iconKeyActive: "generate-f",
},
{
label: "send",
page: "/tabs/send",
iconKey: "send",
iconKeyActive: "send-f",
},
{
label: "settings",
page: "/tabs/settings",
iconKey: "cog",
iconKeyActive: "cog-f",
showBerry: onboardingFeatureEnabled && !nudgeStatus.hasSpotlightDismissed,
},
];
}),
);
async ngOnInit() {
this.activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId));
this.navButtons$ = combineLatest([
this.configService.getFeatureFlag$(FeatureFlag.PM8851_BrowserOnboardingNudge),
this.vaultNudgesService.hasActiveBadges$(this.activeUserId),
]).pipe(
map(([onboardingFeatureEnabled, hasBadges]) => {
return [
{
label: "vault",
page: "/tabs/vault",
iconKey: "lock",
iconKeyActive: "lock-f",
},
{
label: "generator",
page: "/tabs/generator",
iconKey: "generate",
iconKeyActive: "generate-f",
},
{
label: "send",
page: "/tabs/send",
iconKey: "send",
iconKeyActive: "send-f",
},
{
label: "settings",
page: "/tabs/settings",
iconKey: "cog",
iconKeyActive: "cog-f",
showBerry: onboardingFeatureEnabled && hasBadges,
},
];
}),
);
}
}