Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-11000] AnonLayout Icon/Logo theme refactor #10549

Merged
merged 8 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
import { CommonModule } from "@angular/common";
import { Component, OnDestroy, OnInit } from "@angular/core";
import { ActivatedRoute, Data, NavigationEnd, Router, RouterModule } from "@angular/router";
import { Subject, filter, firstValueFrom, switchMap, takeUntil, tap } from "rxjs";
import { Subject, filter, switchMap, takeUntil, tap } from "rxjs";

Check warning on line 4 in apps/browser/src/auth/popup/extension-anon-layout-wrapper/extension-anon-layout-wrapper.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/auth/popup/extension-anon-layout-wrapper/extension-anon-layout-wrapper.component.ts#L4

Added line #L4 was not covered by tests

import {
AnonLayoutComponent,
AnonLayoutWrapperData,
AnonLayoutWrapperDataService,
} from "@bitwarden/auth/angular";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { ThemeStateService } from "@bitwarden/common/platform/theming/theme-state.service";
import { Icon, IconModule } from "@bitwarden/components";

import { PopOutComponent } from "../../../platform/popup/components/pop-out.component";
import { PopupHeaderComponent } from "../../../platform/popup/layout/popup-header.component";
import { PopupPageComponent } from "../../../platform/popup/layout/popup-page.component";
import { CurrentAccountComponent } from "../account-switching/current-account.component";

import {
ExtensionBitwardenLogoPrimary,
ExtensionBitwardenLogoWhite,
} from "./extension-bitwarden-logo.icon";
import { ExtensionBitwardenLogo } from "./extension-bitwarden-logo.icon";

Check warning on line 19 in apps/browser/src/auth/popup/extension-anon-layout-wrapper/extension-anon-layout-wrapper.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/auth/popup/extension-anon-layout-wrapper/extension-anon-layout-wrapper.component.ts#L19

Added line #L19 was not covered by tests

export interface ExtensionAnonLayoutWrapperData extends AnonLayoutWrapperData {
showAcctSwitcher?: boolean;
Expand Down Expand Up @@ -56,14 +52,13 @@
protected maxWidth: "md" | "3xl";

protected theme: string;
protected logo: Icon;
protected logo = ExtensionBitwardenLogo;

Check warning on line 55 in apps/browser/src/auth/popup/extension-anon-layout-wrapper/extension-anon-layout-wrapper.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/auth/popup/extension-anon-layout-wrapper/extension-anon-layout-wrapper.component.ts#L55

Added line #L55 was not covered by tests

constructor(
private router: Router,
private route: ActivatedRoute,
private i18nService: I18nService,
private extensionAnonLayoutWrapperDataService: AnonLayoutWrapperDataService,
private themeStateService: ThemeStateService,
) {}

async ngOnInit(): Promise<void> {
Expand All @@ -73,14 +68,6 @@
// Listen for page changes and update the page data appropriately
this.listenForPageDataChanges();
this.listenForServiceDataChanges();

this.theme = await firstValueFrom(this.themeStateService.selectedTheme$);

if (this.theme === "dark") {
this.logo = ExtensionBitwardenLogoWhite;
} else {
this.logo = ExtensionBitwardenLogoPrimary;
}
}

private listenForPageDataChanges() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import {
} from "@bitwarden/common/platform/abstractions/environment.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { ThemeType } from "@bitwarden/common/platform/enums";
import { ThemeStateService } from "@bitwarden/common/platform/theming/theme-state.service";
import { UserId } from "@bitwarden/common/types/guid";
import { ButtonModule, I18nMockService } from "@bitwarden/components";

Expand All @@ -47,7 +45,6 @@ const decorators = (options: {
applicationVersion?: string;
clientType?: ClientType;
hostName?: string;
themeType?: ThemeType;
}) => {
return [
componentWrapperDecorator(
Expand Down Expand Up @@ -120,12 +117,6 @@ const decorators = (options: {
getClientType: () => options.clientType || ClientType.Web,
} as Partial<PlatformUtilsService>,
},
{
provide: ThemeStateService,
useValue: {
selectedTheme$: of(options.themeType || ThemeType.Light),
} as Partial<ThemeStateService>,
},
{
provide: I18nService,
useFactory: () => {
Expand Down

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion apps/desktop/desktop_native/napi/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export namespace processisolations {
export function isCoreDumpingDisabled(): Promise<boolean>
export function disableMemoryAccess(): Promise<void>
}

export namespace powermonitors {
export function onLock(callback: (err: Error | null, ) => any): Promise<void>
export function isLockMonitorAvailable(): Promise<boolean>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import {
Environment,
} from "@bitwarden/common/platform/abstractions/environment.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { ThemeType } from "@bitwarden/common/platform/enums";
import { ThemeStateService } from "@bitwarden/common/platform/theming/theme-state.service";
import { ButtonModule } from "@bitwarden/components";

// FIXME: remove `/apps` import from `/libs`
Expand All @@ -40,7 +38,6 @@ const decorators = (options: {
applicationVersion?: string;
clientType?: ClientType;
hostName?: string;
themeType?: ThemeType;
}) => {
return [
componentWrapperDecorator(
Expand Down Expand Up @@ -84,12 +81,6 @@ const decorators = (options: {
getClientType: () => options.clientType || ClientType.Web,
} as Partial<PlatformUtilsService>,
},
{
provide: ThemeStateService,
useValue: {
selectedTheme$: of(options.themeType || ThemeType.Light),
} as Partial<ThemeStateService>,
},
],
}),
applicationConfig({
Expand Down
42 changes: 7 additions & 35 deletions libs/auth/src/angular/anon-layout/anon-layout.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
import { ClientType } from "@bitwarden/common/enums";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { ThemeStateService } from "@bitwarden/common/platform/theming/theme-state.service";

import { IconModule, Icon } from "../../../../components/src/icon";
import { SharedModule } from "../../../../components/src/shared";
import { TypographyModule } from "../../../../components/src/typography";
import { BitwardenLogoPrimary, BitwardenLogoWhite } from "../icons";
import { BitwardenShieldPrimary, BitwardenShieldWhite } from "../icons/bitwarden-shield.icon";
import { BitwardenLogo, BitwardenShield } from "../icons";

Check warning on line 12 in libs/auth/src/angular/anon-layout/anon-layout.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/auth/src/angular/anon-layout/anon-layout.component.ts#L12

Added line #L12 was not covered by tests

@Component({
standalone: true,
Expand All @@ -34,20 +32,17 @@
*/
@Input() maxWidth: "md" | "3xl" = "md";

protected logo: Icon;

protected logo = BitwardenLogo;

Check warning on line 35 in libs/auth/src/angular/anon-layout/anon-layout.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/auth/src/angular/anon-layout/anon-layout.component.ts#L35

Added line #L35 was not covered by tests
protected year = "2024";
protected clientType: ClientType;
protected hostname: string;
protected version: string;
protected theme: string;

protected hideYearAndVersion = false;

constructor(
private environmentService: EnvironmentService,
private platformUtilsService: PlatformUtilsService,
private themeStateService: ThemeStateService,
) {
this.year = new Date().getFullYear().toString();
this.clientType = this.platformUtilsService.getClientType();
Expand All @@ -56,41 +51,18 @@

async ngOnInit() {
this.maxWidth = this.maxWidth ?? "md";

this.theme = await firstValueFrom(this.themeStateService.selectedTheme$);

if (this.theme === "dark") {
this.logo = BitwardenLogoWhite;
} else {
this.logo = BitwardenLogoPrimary;
}

await this.updateIcon(this.theme);

this.hostname = (await firstValueFrom(this.environmentService.environment$)).getHostname();
this.version = await this.platformUtilsService.getApplicationVersion();
}

async ngOnChanges(changes: SimpleChanges) {
if (changes.icon) {
const theme = await firstValueFrom(this.themeStateService.selectedTheme$);
await this.updateIcon(theme);
// If there is no icon input, then use the default icon
if (this.icon == null) {
this.icon = BitwardenShield;

Check warning on line 59 in libs/auth/src/angular/anon-layout/anon-layout.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/auth/src/angular/anon-layout/anon-layout.component.ts#L59

Added line #L59 was not covered by tests
}
}

async ngOnChanges(changes: SimpleChanges) {
if (changes.maxWidth) {
this.maxWidth = changes.maxWidth.currentValue ?? "md";
}
}

private async updateIcon(theme: string) {
if (this.icon == null) {
if (theme === "dark") {
this.icon = BitwardenShieldWhite;
}

if (theme !== "dark") {
this.icon = BitwardenShieldPrimary;
}
}
}
}
9 changes: 1 addition & 8 deletions libs/auth/src/angular/anon-layout/anon-layout.stories.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Meta, StoryObj, moduleMetadata } from "@storybook/angular";
import { BehaviorSubject, of } from "rxjs";
import { BehaviorSubject } from "rxjs";

Check warning on line 3 in libs/auth/src/angular/anon-layout/anon-layout.stories.ts

View check run for this annotation

Codecov / codecov/patch

libs/auth/src/angular/anon-layout/anon-layout.stories.ts#L2-L3

Added lines #L2 - L3 were not covered by tests
import { ClientType } from "@bitwarden/common/enums";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { ThemeStateService } from "@bitwarden/common/platform/theming/theme-state.service";

import { ButtonModule } from "../../../../components/src/button";
import { I18nMockService } from "../../../../components/src/utils/i18n-mock.service";
Expand Down Expand Up @@ -47,12 +46,6 @@
}).asObservable(),
},
},
{
provide: ThemeStateService,
useValue: {
selectedTheme$: of("light"),
},
},
],
}),
],
Expand Down
Loading
Loading