-
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add guard to show confirm message
- Loading branch information
1 parent
7a0ef96
commit 1c98c4e
Showing
14 changed files
with
88 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { ActivatedRouteSnapshot, CanDeactivate, RouterStateSnapshot } from '@angular/router'; | ||
import { Injectable } from '@angular/core'; | ||
import { Store } from '@ngrx/store'; | ||
import { GlobalActions } from '@mm-actions/global'; | ||
import { Selectors } from '@mm-selectors/index'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class TrainingCardDeactivationGuardProvider implements CanDeactivate<any> { | ||
private globalActions; | ||
|
||
|
||
constructor(private store: Store) { | ||
this.globalActions = new GlobalActions(store); | ||
} | ||
|
||
canDeactivate( | ||
component: any, | ||
currentRoute: ActivatedRouteSnapshot, | ||
currentState: RouterStateSnapshot, | ||
nextState: RouterStateSnapshot, | ||
) { | ||
let trainingCardOpen = false; | ||
|
||
this.store | ||
.select(Selectors.getTrainingCard) | ||
.subscribe(trainingCard => { | ||
trainingCardOpen = trainingCard.isOpen; | ||
}).unsubscribe(); | ||
|
||
if (trainingCardOpen) { | ||
this.globalActions.setTrainingCard({ isOpen: true, showConfirmExit: true, nextUrl: nextState.url }); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters