]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - can-deactivate-guard.service.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / can-deactivate-guard.service.ts
... / ...
CommitLineData
1import { Observable } from 'rxjs'
2import { Injectable } from '@angular/core'
3import { ConfirmService } from '@app/core/confirm'
4
5export type CanComponentDeactivateResult = { text?: string, canDeactivate: Observable<boolean> | boolean }
6
7export interface CanComponentDeactivate {
8 canDeactivate: () => CanComponentDeactivateResult
9}
10
11@Injectable()
12export 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}