]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/guards/can-deactivate-guard.service.ts
Improve blacklist management
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / guards / can-deactivate-guard.service.ts
CommitLineData
529479f9 1import { Injectable } from '@angular/core'
db400f44
C
2import { ActivatedRouteSnapshot, CanDeactivate, RouterStateSnapshot } from '@angular/router'
3import { Observable } from 'rxjs'
f6a043df 4import { ConfirmService } from '../../core/index'
b1d40cff 5import { I18n } from '@ngx-translate/i18n-polyfill'
529479f9
DG
6
7export interface CanComponentDeactivate {
f6a043df 8 canDeactivate: () => { text?: string, canDeactivate: Observable<boolean> | boolean }
529479f9
DG
9}
10
11@Injectable()
12export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate> {
b1d40cff
C
13 constructor (
14 private confirmService: ConfirmService,
15 private i18n: I18n
16 ) { }
529479f9
DG
17
18 canDeactivate (component: CanComponentDeactivate,
19 currentRoute: ActivatedRouteSnapshot,
20 currentState: RouterStateSnapshot,
21 nextState: RouterStateSnapshot
1f30a185 22 ) {
f6a043df 23 const result = component.canDeactivate()
b1d40cff 24 const text = result.text || this.i18n('All unsaved data will be lost, are you sure you want to leave this page?')
f6a043df
C
25
26 return result.canDeactivate || this.confirmService.confirm(
27 text,
b1d40cff 28 this.i18n('Warning')
529479f9
DG
29 )
30 }
31
32}