aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/root.component.ts
diff options
context:
space:
mode:
authorKimsible <kimsible@users.noreply.github.com>2021-04-28 22:17:02 +0200
committerKimsible <kimsible@users.noreply.github.com>2021-05-05 11:47:03 +0200
commit69e076ddb0deda9e4120bab095d3369bb19fbd1e (patch)
tree6576a6293b9e76ce385813f62376e15a7e05001f /client/src/app/root.component.ts
parent08ac081b37cd6115634e8951608116fe0f13032b (diff)
downloadPeerTube-69e076ddb0deda9e4120bab095d3369bb19fbd1e.tar.gz
PeerTube-69e076ddb0deda9e4120bab095d3369bb19fbd1e.tar.zst
PeerTube-69e076ddb0deda9e4120bab095d3369bb19fbd1e.zip
Refactor client @actorName matcher with new API route
Diffstat (limited to 'client/src/app/root.component.ts')
-rw-r--r--client/src/app/root.component.ts42
1 files changed, 42 insertions, 0 deletions
diff --git a/client/src/app/root.component.ts b/client/src/app/root.component.ts
new file mode 100644
index 000000000..c65f59448
--- /dev/null
+++ b/client/src/app/root.component.ts
@@ -0,0 +1,42 @@
1import { Component, OnInit } from '@angular/core'
2import { catchError, distinctUntilChanged, map, switchMap } from 'rxjs/operators'
3import { ActivatedRoute, Router } from '@angular/router'
4import { RestExtractor } from '@app/core'
5import { ActorService } from '@app/shared/shared-main/account'
6import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
7
8@Component({
9 selector: 'my-root',
10 template: ''
11})
12export class RootComponent implements OnInit {
13 constructor (
14 private actorService: ActorService,
15 private route: ActivatedRoute,
16 private restExtractor: RestExtractor,
17 private router: Router
18 ) {
19 }
20
21 ngOnInit () {
22 this.route.params
23 .pipe(
24 map(params => params[ 'actorName' ]),
25 distinctUntilChanged(),
26 switchMap(actorName => this.actorService.getActor(actorName)),
27 catchError(err => this.restExtractor.redirectTo404IfNotFound(err, 'other', [
28 HttpStatusCode.BAD_REQUEST_400,
29 HttpStatusCode.NOT_FOUND_404
30 ]))
31 )
32 .subscribe(actor => {
33 if (actor.constructor.name === 'Account') {
34 this.router.navigateByUrl(`/accounts/${actor.name}`)
35 }
36
37 if (actor.constructor.name === 'VideoChannel') {
38 this.router.navigateByUrl(`/video-channels/${actor.name}`)
39 }
40 })
41 }
42}