mirror of
https://github.com/bitwarden/browser.git
synced 2024-08-29 23:49:50 +02:00
Add premium and unless-premium directives (#710)
This commit is contained in:
parent
744649573a
commit
f7375e9064
27
angular/src/directives/not-premium.directive.ts
Normal file
27
angular/src/directives/not-premium.directive.ts
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
import { Directive, OnInit, TemplateRef, ViewContainerRef } from "@angular/core";
|
||||||
|
|
||||||
|
import { StateService } from "jslib-common/abstractions/state.service";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hides the element if the user has premium.
|
||||||
|
*/
|
||||||
|
@Directive({
|
||||||
|
selector: "[appNotPremium]",
|
||||||
|
})
|
||||||
|
export class NotPremiumDirective implements OnInit {
|
||||||
|
constructor(
|
||||||
|
private templateRef: TemplateRef<any>,
|
||||||
|
private viewContainer: ViewContainerRef,
|
||||||
|
private stateService: StateService
|
||||||
|
) {}
|
||||||
|
|
||||||
|
async ngOnInit(): Promise<void> {
|
||||||
|
const premium = await this.stateService.getCanAccessPremium();
|
||||||
|
|
||||||
|
if (premium) {
|
||||||
|
this.viewContainer.clear();
|
||||||
|
} else {
|
||||||
|
this.viewContainer.createEmbeddedView(this.templateRef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
angular/src/directives/premium.directive.ts
Normal file
27
angular/src/directives/premium.directive.ts
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
import { Directive, OnInit, TemplateRef, ViewContainerRef } from "@angular/core";
|
||||||
|
|
||||||
|
import { StateService } from "jslib-common/abstractions/state.service";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only shows the element if the user has premium.
|
||||||
|
*/
|
||||||
|
@Directive({
|
||||||
|
selector: "[appPremium]",
|
||||||
|
})
|
||||||
|
export class PremiumDirective implements OnInit {
|
||||||
|
constructor(
|
||||||
|
private templateRef: TemplateRef<any>,
|
||||||
|
private viewContainer: ViewContainerRef,
|
||||||
|
private stateService: StateService
|
||||||
|
) {}
|
||||||
|
|
||||||
|
async ngOnInit(): Promise<void> {
|
||||||
|
const premium = await this.stateService.getCanAccessPremium();
|
||||||
|
|
||||||
|
if (premium) {
|
||||||
|
this.viewContainer.createEmbeddedView(this.templateRef);
|
||||||
|
} else {
|
||||||
|
this.viewContainer.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user