-import { Component, OnInit } from '@angular/core'
+import { Component, OnInit, OnDestroy } from '@angular/core'
import { ActivatedRoute } from '@angular/router'
import { Account } from '@app/shared/account/account.model'
import { AccountService } from '@app/shared/account/account.service'
import { I18n } from '@ngx-translate/i18n-polyfill'
+import { Subscription } from 'rxjs'
@Component({
selector: 'my-account-about',
templateUrl: './account-about.component.html',
styleUrls: [ './account-about.component.scss' ]
})
-export class AccountAboutComponent implements OnInit {
+export class AccountAboutComponent implements OnInit, OnDestroy {
account: Account
+ private accountSub: Subscription
+
constructor (
private route: ActivatedRoute,
private i18n: I18n,
ngOnInit () {
// Parent get the account for us
- this.accountService.accountLoaded
+ this.accountSub = this.accountService.accountLoaded
.subscribe(account => this.account = account)
}
+ ngOnDestroy () {
+ if (this.accountSub) this.accountSub.unsubscribe()
+ }
+
getAccountDescription () {
if (this.account.description) return this.account.description
-import { Component, OnInit } from '@angular/core'
+import { Component, OnDestroy, OnInit } from '@angular/core'
import { ActivatedRoute } from '@angular/router'
import { Account } from '@app/shared/account/account.model'
import { AccountService } from '@app/shared/account/account.service'
import { VideoChannel } from '../../../../../shared/models/videos'
import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
import { flatMap, map, tap } from 'rxjs/operators'
+import { Subscription } from 'rxjs'
@Component({
selector: 'my-account-video-channels',
templateUrl: './account-video-channels.component.html',
styleUrls: [ './account-video-channels.component.scss' ]
})
-export class AccountVideoChannelsComponent implements OnInit {
+export class AccountVideoChannelsComponent implements OnInit, OnDestroy {
account: Account
videoChannels: VideoChannel[] = []
+ private accountSub: Subscription
+
constructor (
protected route: ActivatedRoute,
private accountService: AccountService,
ngOnInit () {
// Parent get the account for us
- this.accountService.accountLoaded
+ this.accountSub = this.accountService.accountLoaded
.pipe(
tap(account => this.account = account),
flatMap(account => this.videoChannelService.listAccountVideoChannels(account)),
)
.subscribe(videoChannels => this.videoChannels = videoChannels)
}
+
+ ngOnDestroy () {
+ if (this.accountSub) this.accountSub.unsubscribe()
+ }
}
import { AccountService } from '@app/shared/account/account.service'
import { tap } from 'rxjs/operators'
import { I18n } from '@ngx-translate/i18n-polyfill'
+import { Subscription } from 'rxjs'
@Component({
selector: 'my-account-videos',
loadOnInit = false
private account: Account
+ private accountSub: Subscription
constructor (
protected router: Router,
super.ngOnInit()
// Parent get the account for us
- this.accountService.accountLoaded
+ this.accountSub = this.accountService.accountLoaded
.subscribe(account => {
this.account = account
- this.currentRoute = '/account/' + this.account.id + '/videos'
+ this.currentRoute = '/account/' + this.account.nameWithHost + '/videos'
- this.loadMoreVideos(this.pagination.currentPage)
+ this.reloadVideos()
this.generateSyndicationList()
})
}
ngOnDestroy () {
+ if (this.accountSub) this.accountSub.unsubscribe()
+
super.ngOnDestroy()
}
import { AccountService } from '@app/shared/account/account.service'
import { Account } from '@app/shared/account/account.model'
import { RestExtractor } from '@app/shared'
-import { catchError } from 'rxjs/operators'
+import { catchError, switchMap, distinctUntilChanged, map } from 'rxjs/operators'
+import { Subscription } from 'rxjs'
@Component({
templateUrl: './accounts.component.html',
export class AccountsComponent implements OnInit {
account: Account
+ private routeSub: Subscription
+
constructor (
private route: ActivatedRoute,
private accountService: AccountService,
) {}
ngOnInit () {
- const accountId = this.route.snapshot.params['accountId']
+ this.routeSub = this.route.params
+ .pipe(
+ map(params => params[ 'accountId' ]),
+ distinctUntilChanged(),
+ switchMap(accountId => this.accountService.getAccount(accountId)),
+ catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ]))
+ )
+ .subscribe(account => this.account = account)
+ }
- this.accountService.getAccount(accountId)
- .pipe(catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ])))
- .subscribe(account => this.account = account)
+ ngOnDestroy () {
+ if (this.routeSub) this.routeSub.unsubscribe()
}
}
-import { Component, OnInit } from '@angular/core'
+import { Component, OnDestroy, OnInit } from '@angular/core'
import { ActivatedRoute } from '@angular/router'
import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
import { I18n } from '@ngx-translate/i18n-polyfill'
+import { Subscription } from 'rxjs'
@Component({
selector: 'my-video-channel-about',
templateUrl: './video-channel-about.component.html',
styleUrls: [ './video-channel-about.component.scss' ]
})
-export class VideoChannelAboutComponent implements OnInit {
+export class VideoChannelAboutComponent implements OnInit, OnDestroy {
videoChannel: VideoChannel
+ private videoChannelSub: Subscription
+
constructor (
private route: ActivatedRoute,
private i18n: I18n,
ngOnInit () {
// Parent get the video channel for us
- this.videoChannelService.videoChannelLoaded
+ this.videoChannelSub = this.videoChannelService.videoChannelLoaded
.subscribe(videoChannel => this.videoChannel = videoChannel)
}
+ ngOnDestroy () {
+ if (this.videoChannelSub) this.videoChannelSub.unsubscribe()
+ }
+
getVideoChannelDescription () {
if (this.videoChannel.description) return this.videoChannel.description
import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
import { tap } from 'rxjs/operators'
import { I18n } from '@ngx-translate/i18n-polyfill'
+import { Subscription } from 'rxjs'
@Component({
selector: 'my-video-channel-videos',
loadOnInit = false
private videoChannel: VideoChannel
+ private videoChannelSub: Subscription
constructor (
protected router: Router,
super.ngOnInit()
// Parent get the video channel for us
- this.videoChannelService.videoChannelLoaded
+ this.videoChannelSub = this.videoChannelService.videoChannelLoaded
.subscribe(videoChannel => {
this.videoChannel = videoChannel
this.currentRoute = '/video-channel/' + this.videoChannel.uuid + '/videos'
- this.loadMoreVideos(this.pagination.currentPage)
+ this.reloadVideos()
this.generateSyndicationList()
})
}
ngOnDestroy () {
+ if (this.videoChannelSub) this.videoChannelSub.unsubscribe()
+
super.ngOnDestroy()
}
-import { Component, OnInit } from '@angular/core'
+import { Component, OnInit, OnDestroy } from '@angular/core'
import { ActivatedRoute } from '@angular/router'
import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
import { RestExtractor } from '@app/shared'
-import { catchError } from 'rxjs/operators'
+import { catchError, switchMap, map, distinctUntilChanged } from 'rxjs/operators'
+import { Subscription } from 'rxjs/Subscription'
@Component({
templateUrl: './video-channels.component.html',
styleUrls: [ './video-channels.component.scss' ]
})
-export class VideoChannelsComponent implements OnInit {
+export class VideoChannelsComponent implements OnInit, OnDestroy {
videoChannel: VideoChannel
+ private routeSub: Subscription
+
constructor (
private route: ActivatedRoute,
private videoChannelService: VideoChannelService,
private restExtractor: RestExtractor
- ) {}
+ ) { }
ngOnInit () {
- const videoChannelId = this.route.snapshot.params['videoChannelId']
+ this.routeSub = this.route.params
+ .pipe(
+ map(params => params[ 'videoChannelId' ]),
+ distinctUntilChanged(),
+ switchMap(videoChannelId => this.videoChannelService.getVideoChannel(videoChannelId)),
+ catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ]))
+ )
+ .subscribe(videoChannel => this.videoChannel = videoChannel)
+
+ }
- this.videoChannelService.getVideoChannel(videoChannelId)
- .pipe(catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ])))
- .subscribe(videoChannel => this.videoChannel = videoChannel)
+ ngOnDestroy () {
+ if (this.routeSub) this.routeSub.unsubscribe()
}
}
}
private avoidTruncatedLinks (html: string) {
- console.log(html)
return html.replace(/<a[^>]+>([^<]+)<\/a>\s*...((<\/p>)|(<\/li>)|(<\/strong>))?$/mi, '$1...')
}
}