45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
|
import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core';
|
||
|
import { UserService } from '@ghostfolio/client/services/user/user.service';
|
||
|
import { User } from '@ghostfolio/common/interfaces';
|
||
|
import { Subject } from 'rxjs';
|
||
|
import { takeUntil } from 'rxjs/operators';
|
||
|
|
||
|
@Component({
|
||
|
selector: 'gf-portfolio-page',
|
||
|
templateUrl: './portfolio-page.html',
|
||
|
styleUrls: ['./portfolio-page.scss']
|
||
|
})
|
||
|
export class PortfolioPageComponent implements OnDestroy, OnInit {
|
||
|
public user: User;
|
||
|
|
||
|
private unsubscribeSubject = new Subject<void>();
|
||
|
|
||
|
/**
|
||
|
* @constructor
|
||
|
*/
|
||
|
public constructor(
|
||
|
private changeDetectorRef: ChangeDetectorRef,
|
||
|
private userService: UserService
|
||
|
) {}
|
||
|
|
||
|
/**
|
||
|
* Initializes the controller
|
||
|
*/
|
||
|
public ngOnInit() {
|
||
|
this.userService.stateChanged
|
||
|
.pipe(takeUntil(this.unsubscribeSubject))
|
||
|
.subscribe((state) => {
|
||
|
if (state?.user) {
|
||
|
this.user = state.user;
|
||
|
|
||
|
this.changeDetectorRef.markForCheck();
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public ngOnDestroy() {
|
||
|
this.unsubscribeSubject.next();
|
||
|
this.unsubscribeSubject.complete();
|
||
|
}
|
||
|
}
|