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