aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/can-deactivate-guard.service.ts
diff options
context:
space:
mode:
authorDimitri Gilbert <dimitri.gilbert@gmail.com>2018-01-25 18:40:23 +0100
committerChocobozzz <me@florianbigard.com>2018-01-25 18:40:23 +0100
commit529479f924b1849423fb087f9699f8ecb20610ca (patch)
tree3d65b27cb34f3cc187c1bb3af867b254166fee2e /client/src/app/shared/can-deactivate-guard.service.ts
parentc360c49456a27529268722fb7c645819cff59486 (diff)
downloadPeerTube-529479f924b1849423fb087f9699f8ecb20610ca.tar.gz
PeerTube-529479f924b1849423fb087f9699f8ecb20610ca.tar.zst
PeerTube-529479f924b1849423fb087f9699f8ecb20610ca.zip
Issue #195 : When uploading, warn when the user quits the page (#222)
* issue #195 * fixing missing provider definition * fix styling issue * fix styling issue * removed unecessary code * using angular confirmService instead of window.confirm * gitignore unecessary folders * style fixes * using a generic canDeactivateGuard * fixing lint style
Diffstat (limited to 'client/src/app/shared/can-deactivate-guard.service.ts')
-rw-r--r--client/src/app/shared/can-deactivate-guard.service.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/client/src/app/shared/can-deactivate-guard.service.ts b/client/src/app/shared/can-deactivate-guard.service.ts
new file mode 100644
index 000000000..4239df737
--- /dev/null
+++ b/client/src/app/shared/can-deactivate-guard.service.ts
@@ -0,0 +1,25 @@
1import { Injectable } from '@angular/core'
2import { CanDeactivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'
3import { Observable } from 'rxjs/Observable'
4import { ConfirmService } from '../core'
5
6export interface CanComponentDeactivate {
7 canDeactivate: () => Observable<boolean> | boolean
8}
9
10@Injectable()
11export 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}