Fix account/channel pages route subscription

This commit is contained in:
Chocobozzz 2018-06-07 11:19:26 +02:00
parent cc69c8db39
commit 734a5ceb3d
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
8 changed files with 77 additions and 28 deletions

View File

@ -1,17 +1,20 @@
import { Component, OnInit } from '@angular/core' import { Component, OnInit, OnDestroy } from '@angular/core'
import { ActivatedRoute } from '@angular/router' import { ActivatedRoute } from '@angular/router'
import { Account } from '@app/shared/account/account.model' import { Account } from '@app/shared/account/account.model'
import { AccountService } from '@app/shared/account/account.service' import { AccountService } from '@app/shared/account/account.service'
import { I18n } from '@ngx-translate/i18n-polyfill' import { I18n } from '@ngx-translate/i18n-polyfill'
import { Subscription } from 'rxjs'
@Component({ @Component({
selector: 'my-account-about', selector: 'my-account-about',
templateUrl: './account-about.component.html', templateUrl: './account-about.component.html',
styleUrls: [ './account-about.component.scss' ] styleUrls: [ './account-about.component.scss' ]
}) })
export class AccountAboutComponent implements OnInit { export class AccountAboutComponent implements OnInit, OnDestroy {
account: Account account: Account
private accountSub: Subscription
constructor ( constructor (
private route: ActivatedRoute, private route: ActivatedRoute,
private i18n: I18n, private i18n: I18n,
@ -20,10 +23,14 @@ export class AccountAboutComponent implements OnInit {
ngOnInit () { ngOnInit () {
// Parent get the account for us // Parent get the account for us
this.accountService.accountLoaded this.accountSub = this.accountService.accountLoaded
.subscribe(account => this.account = account) .subscribe(account => this.account = account)
} }
ngOnDestroy () {
if (this.accountSub) this.accountSub.unsubscribe()
}
getAccountDescription () { getAccountDescription () {
if (this.account.description) return this.account.description if (this.account.description) return this.account.description

View File

@ -1,20 +1,23 @@
import { Component, OnInit } from '@angular/core' import { Component, OnDestroy, OnInit } from '@angular/core'
import { ActivatedRoute } from '@angular/router' import { ActivatedRoute } from '@angular/router'
import { Account } from '@app/shared/account/account.model' import { Account } from '@app/shared/account/account.model'
import { AccountService } from '@app/shared/account/account.service' import { AccountService } from '@app/shared/account/account.service'
import { VideoChannel } from '../../../../../shared/models/videos' import { VideoChannel } from '../../../../../shared/models/videos'
import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
import { flatMap, map, tap } from 'rxjs/operators' import { flatMap, map, tap } from 'rxjs/operators'
import { Subscription } from 'rxjs'
@Component({ @Component({
selector: 'my-account-video-channels', selector: 'my-account-video-channels',
templateUrl: './account-video-channels.component.html', templateUrl: './account-video-channels.component.html',
styleUrls: [ './account-video-channels.component.scss' ] styleUrls: [ './account-video-channels.component.scss' ]
}) })
export class AccountVideoChannelsComponent implements OnInit { export class AccountVideoChannelsComponent implements OnInit, OnDestroy {
account: Account account: Account
videoChannels: VideoChannel[] = [] videoChannels: VideoChannel[] = []
private accountSub: Subscription
constructor ( constructor (
protected route: ActivatedRoute, protected route: ActivatedRoute,
private accountService: AccountService, private accountService: AccountService,
@ -23,7 +26,7 @@ export class AccountVideoChannelsComponent implements OnInit {
ngOnInit () { ngOnInit () {
// Parent get the account for us // Parent get the account for us
this.accountService.accountLoaded this.accountSub = this.accountService.accountLoaded
.pipe( .pipe(
tap(account => this.account = account), tap(account => this.account = account),
flatMap(account => this.videoChannelService.listAccountVideoChannels(account)), flatMap(account => this.videoChannelService.listAccountVideoChannels(account)),
@ -31,4 +34,8 @@ export class AccountVideoChannelsComponent implements OnInit {
) )
.subscribe(videoChannels => this.videoChannels = videoChannels) .subscribe(videoChannels => this.videoChannels = videoChannels)
} }
ngOnDestroy () {
if (this.accountSub) this.accountSub.unsubscribe()
}
} }

View File

@ -11,6 +11,7 @@ import { Account } from '@app/shared/account/account.model'
import { AccountService } from '@app/shared/account/account.service' import { AccountService } from '@app/shared/account/account.service'
import { tap } from 'rxjs/operators' import { tap } from 'rxjs/operators'
import { I18n } from '@ngx-translate/i18n-polyfill' import { I18n } from '@ngx-translate/i18n-polyfill'
import { Subscription } from 'rxjs'
@Component({ @Component({
selector: 'my-account-videos', selector: 'my-account-videos',
@ -27,6 +28,7 @@ export class AccountVideosComponent extends AbstractVideoList implements OnInit,
loadOnInit = false loadOnInit = false
private account: Account private account: Account
private accountSub: Subscription
constructor ( constructor (
protected router: Router, protected router: Router,
@ -48,17 +50,19 @@ export class AccountVideosComponent extends AbstractVideoList implements OnInit,
super.ngOnInit() super.ngOnInit()
// Parent get the account for us // Parent get the account for us
this.accountService.accountLoaded this.accountSub = this.accountService.accountLoaded
.subscribe(account => { .subscribe(account => {
this.account = 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() this.generateSyndicationList()
}) })
} }
ngOnDestroy () { ngOnDestroy () {
if (this.accountSub) this.accountSub.unsubscribe()
super.ngOnDestroy() super.ngOnDestroy()
} }

View File

@ -3,7 +3,8 @@ import { ActivatedRoute } from '@angular/router'
import { AccountService } from '@app/shared/account/account.service' import { AccountService } from '@app/shared/account/account.service'
import { Account } from '@app/shared/account/account.model' import { Account } from '@app/shared/account/account.model'
import { RestExtractor } from '@app/shared' import { RestExtractor } from '@app/shared'
import { catchError } from 'rxjs/operators' import { catchError, switchMap, distinctUntilChanged, map } from 'rxjs/operators'
import { Subscription } from 'rxjs'
@Component({ @Component({
templateUrl: './accounts.component.html', templateUrl: './accounts.component.html',
@ -12,6 +13,8 @@ import { catchError } from 'rxjs/operators'
export class AccountsComponent implements OnInit { export class AccountsComponent implements OnInit {
account: Account account: Account
private routeSub: Subscription
constructor ( constructor (
private route: ActivatedRoute, private route: ActivatedRoute,
private accountService: AccountService, private accountService: AccountService,
@ -19,10 +22,17 @@ export class AccountsComponent implements OnInit {
) {} ) {}
ngOnInit () { 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) ngOnDestroy () {
.pipe(catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ]))) if (this.routeSub) this.routeSub.unsubscribe()
.subscribe(account => this.account = account)
} }
} }

View File

@ -1,17 +1,20 @@
import { Component, OnInit } from '@angular/core' import { Component, OnDestroy, OnInit } from '@angular/core'
import { ActivatedRoute } from '@angular/router' import { ActivatedRoute } from '@angular/router'
import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
import { VideoChannel } from '@app/shared/video-channel/video-channel.model' import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
import { I18n } from '@ngx-translate/i18n-polyfill' import { I18n } from '@ngx-translate/i18n-polyfill'
import { Subscription } from 'rxjs'
@Component({ @Component({
selector: 'my-video-channel-about', selector: 'my-video-channel-about',
templateUrl: './video-channel-about.component.html', templateUrl: './video-channel-about.component.html',
styleUrls: [ './video-channel-about.component.scss' ] styleUrls: [ './video-channel-about.component.scss' ]
}) })
export class VideoChannelAboutComponent implements OnInit { export class VideoChannelAboutComponent implements OnInit, OnDestroy {
videoChannel: VideoChannel videoChannel: VideoChannel
private videoChannelSub: Subscription
constructor ( constructor (
private route: ActivatedRoute, private route: ActivatedRoute,
private i18n: I18n, private i18n: I18n,
@ -20,10 +23,14 @@ export class VideoChannelAboutComponent implements OnInit {
ngOnInit () { ngOnInit () {
// Parent get the video channel for us // Parent get the video channel for us
this.videoChannelService.videoChannelLoaded this.videoChannelSub = this.videoChannelService.videoChannelLoaded
.subscribe(videoChannel => this.videoChannel = videoChannel) .subscribe(videoChannel => this.videoChannel = videoChannel)
} }
ngOnDestroy () {
if (this.videoChannelSub) this.videoChannelSub.unsubscribe()
}
getVideoChannelDescription () { getVideoChannelDescription () {
if (this.videoChannel.description) return this.videoChannel.description if (this.videoChannel.description) return this.videoChannel.description

View File

@ -11,6 +11,7 @@ import { VideoChannelService } from '@app/shared/video-channel/video-channel.ser
import { VideoChannel } from '@app/shared/video-channel/video-channel.model' import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
import { tap } from 'rxjs/operators' import { tap } from 'rxjs/operators'
import { I18n } from '@ngx-translate/i18n-polyfill' import { I18n } from '@ngx-translate/i18n-polyfill'
import { Subscription } from 'rxjs'
@Component({ @Component({
selector: 'my-video-channel-videos', selector: 'my-video-channel-videos',
@ -27,6 +28,7 @@ export class VideoChannelVideosComponent extends AbstractVideoList implements On
loadOnInit = false loadOnInit = false
private videoChannel: VideoChannel private videoChannel: VideoChannel
private videoChannelSub: Subscription
constructor ( constructor (
protected router: Router, protected router: Router,
@ -48,17 +50,19 @@ export class VideoChannelVideosComponent extends AbstractVideoList implements On
super.ngOnInit() super.ngOnInit()
// Parent get the video channel for us // Parent get the video channel for us
this.videoChannelService.videoChannelLoaded this.videoChannelSub = this.videoChannelService.videoChannelLoaded
.subscribe(videoChannel => { .subscribe(videoChannel => {
this.videoChannel = videoChannel this.videoChannel = videoChannel
this.currentRoute = '/video-channel/' + this.videoChannel.uuid + '/videos' this.currentRoute = '/video-channel/' + this.videoChannel.uuid + '/videos'
this.loadMoreVideos(this.pagination.currentPage) this.reloadVideos()
this.generateSyndicationList() this.generateSyndicationList()
}) })
} }
ngOnDestroy () { ngOnDestroy () {
if (this.videoChannelSub) this.videoChannelSub.unsubscribe()
super.ngOnDestroy() super.ngOnDestroy()
} }

View File

@ -1,28 +1,39 @@
import { Component, OnInit } from '@angular/core' import { Component, OnInit, OnDestroy } from '@angular/core'
import { ActivatedRoute } from '@angular/router' import { ActivatedRoute } from '@angular/router'
import { VideoChannel } from '@app/shared/video-channel/video-channel.model' import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
import { RestExtractor } from '@app/shared' import { RestExtractor } from '@app/shared'
import { catchError } from 'rxjs/operators' import { catchError, switchMap, map, distinctUntilChanged } from 'rxjs/operators'
import { Subscription } from 'rxjs/Subscription'
@Component({ @Component({
templateUrl: './video-channels.component.html', templateUrl: './video-channels.component.html',
styleUrls: [ './video-channels.component.scss' ] styleUrls: [ './video-channels.component.scss' ]
}) })
export class VideoChannelsComponent implements OnInit { export class VideoChannelsComponent implements OnInit, OnDestroy {
videoChannel: VideoChannel videoChannel: VideoChannel
private routeSub: Subscription
constructor ( constructor (
private route: ActivatedRoute, private route: ActivatedRoute,
private videoChannelService: VideoChannelService, private videoChannelService: VideoChannelService,
private restExtractor: RestExtractor private restExtractor: RestExtractor
) {} ) { }
ngOnInit () { 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()
} }
} }

View File

@ -69,7 +69,6 @@ export class MarkdownService {
} }
private avoidTruncatedLinks (html: string) { private avoidTruncatedLinks (html: string) {
console.log(html)
return html.replace(/<a[^>]+>([^<]+)<\/a>\s*...((<\/p>)|(<\/li>)|(<\/strong>))?$/mi, '$1...') return html.replace(/<a[^>]+>([^<]+)<\/a>\s*...((<\/p>)|(<\/li>)|(<\/strong>))?$/mi, '$1...')
} }
} }