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