]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/core/routing/can-deactivate-guard.service.ts
Remove redundant attribute
[github/Chocobozzz/PeerTube.git] / client / src / app / core / routing / can-deactivate-guard.service.ts
CommitLineData
67ed6552 1import { Observable } from 'rxjs'
529479f9 2import { Injectable } from '@angular/core'
23db998f 3import { CanDeactivate } from '@angular/router'
67ed6552 4import { ConfirmService } from '@app/core/confirm'
529479f9 5
c199c427
C
6export type CanComponentDeactivateResult = { text?: string, canDeactivate: Observable<boolean> | boolean }
7
529479f9 8export interface CanComponentDeactivate {
c199c427 9 canDeactivate: () => CanComponentDeactivateResult
529479f9
DG
10}
11
12@Injectable()
13export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate> {
66357162
C
14
15 constructor (private confirmService: ConfirmService) { }
529479f9 16
23db998f 17 canDeactivate (component: CanComponentDeactivate) {
f6a043df 18 const result = component.canDeactivate()
66357162 19 const text = result.text || $localize`All unsaved data will be lost, are you sure you want to leave this page?`
f6a043df
C
20
21 return result.canDeactivate || this.confirmService.confirm(
22 text,
66357162 23 $localize`Warning`
529479f9
DG
24 )
25 }
26
27}