diff --git a/src/main/webapp/app/watchlist/watchlist.component.html b/src/main/webapp/app/watchlist/watchlist.component.html index 50ebf64a0b08234be8c38a9e9ec9dbf8e32f17b3..d0e04b1f7eac4dd400f34a1152dd035ce54a94a2 100644 --- a/src/main/webapp/app/watchlist/watchlist.component.html +++ b/src/main/webapp/app/watchlist/watchlist.component.html @@ -1,5 +1,5 @@ <div > - <div *ngFor="let watchList of myWatchLists">{{watchList.name}} + <div *ngFor="let watchList of getMyWatchLists()">{{watchList.name}} </div> </div> diff --git a/src/main/webapp/app/watchlist/watchlist.component.ts b/src/main/webapp/app/watchlist/watchlist.component.ts index 75e08018068efef5a572337bf15ffd1babd03c61..7b458e4c61fa92ce80109bc1ff2a8f2b789adb61 100644 --- a/src/main/webapp/app/watchlist/watchlist.component.ts +++ b/src/main/webapp/app/watchlist/watchlist.component.ts @@ -2,6 +2,9 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; import { HttpResponse } from '@angular/common/http'; import { UserWatchListService } from '../entities/user-watch-list/user-watch-list.service'; import { IUserWatchList } from 'app/shared/model/user-watch-list.model'; +import { AccountService } from 'app/core/auth/account.service'; +import { Subscription } from 'rxjs'; +import { Account } from 'app/core/user/account.model'; @Component({ @@ -11,16 +14,21 @@ import { IUserWatchList } from 'app/shared/model/user-watch-list.model'; }) export class WatchlistComponent implements OnInit, OnDestroy { + account: Account | null = null; + authSubscription?: Subscription; + myWatchLists: IUserWatchList[] | undefined; constructor( protected watchListService: UserWatchListService, + private accountService: AccountService, + ) { } - - ngOnInit(): void { - if (!this.myWatchLists) { + getMyWatchLists(): IUserWatchList[] { + if(!this.isAuthenticated()) return []; + if (!this.myWatchLists) { this.watchListService.findMyWatchlists().subscribe((data: HttpResponse<IUserWatchList[]>) => { if (data.body) { this.myWatchLists = data.body; @@ -33,11 +41,24 @@ export class WatchlistComponent implements OnInit, OnDestroy { } }) - + return[]; + } else { + return this.myWatchLists; } + } - ngOnDestroy(): void { + ngOnInit(): void { + this.authSubscription = this.accountService.getAuthenticationState().subscribe(account => (this.account = account)); } + isAuthenticated(): boolean { + return this.accountService.isAuthenticated(); + } + + ngOnDestroy(): void { + if (this.authSubscription) { + this.authSubscription.unsubscribe(); + } + } }