PeerTube/client/src/app/+page-not-found/page-not-found.component.ts

47 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-12-03 06:13:46 -06:00
import { Component, OnInit } from '@angular/core'
import { Title } from '@angular/platform-browser'
import { Router } from '@angular/router'
2021-07-16 03:42:24 -05:00
import { HttpStatusCode } from '@shared/models'
2018-05-31 04:35:01 -05:00
@Component({
selector: 'my-page-not-found',
templateUrl: './page-not-found.component.html',
styleUrls: [ './page-not-found.component.scss' ]
})
2020-12-03 06:13:46 -06:00
export class PageNotFoundComponent implements OnInit {
status = HttpStatusCode.NOT_FOUND_404
type: 'video' | 'other' = 'other'
2018-05-31 04:35:01 -05:00
2020-12-03 06:13:46 -06:00
public constructor (
private titleService: Title,
private router: Router
) {
const state = this.router.getCurrentNavigation()?.extras.state
this.type = state?.type || this.type
this.status = state?.obj.status || this.status
}
2020-12-03 06:13:46 -06:00
ngOnInit () {
if (this.pathname.includes('teapot')) {
this.status = HttpStatusCode.I_AM_A_TEAPOT_418
this.titleService.setTitle($localize`I'm a teapot` + ' - PeerTube')
}
}
get pathname () {
return window.location.pathname
}
getMascotName () {
switch (this.status) {
case HttpStatusCode.I_AM_A_TEAPOT_418:
return 'happy'
case HttpStatusCode.FORBIDDEN_403:
return 'arguing'
2020-12-03 06:13:46 -06:00
case HttpStatusCode.NOT_FOUND_404:
default:
return 'defeated'
}
}
2018-05-31 04:35:01 -05:00
}