]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/can-deactivate-guard.service.ts
Issue #195 : When uploading, warn when the user quits the page (#222)
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / can-deactivate-guard.service.ts
1 import { Injectable } from '@angular/core'
2 import { CanDeactivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'
3 import { Observable } from 'rxjs/Observable'
4 import { ConfirmService } from '../core'
5
6 export interface CanComponentDeactivate {
7 canDeactivate: () => Observable<boolean> | boolean
8 }
9
10 @Injectable()
11 export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate> {
12 constructor (private confirmService: ConfirmService) { }
13
14 canDeactivate (component: CanComponentDeactivate,
15 currentRoute: ActivatedRouteSnapshot,
16 currentState: RouterStateSnapshot,
17 nextState: RouterStateSnapshot
18 ): Observable<boolean> | boolean {
19 return component.canDeactivate() || this.confirmService.confirm(
20 'All unsaved data will be lost, are you sure you want to leave ?',
21 'Unsaved Data'
22 )
23 }
24
25 }