Improved redirect url management

This commit is contained in:
Giuseppe Digilio
2019-01-23 13:01:11 +01:00
parent b561bf69e7
commit 1b820ea8ed
2 changed files with 18 additions and 22 deletions

View File

@@ -1,6 +1,6 @@
import { of as observableOf, Observable , Subscription } from 'rxjs';
import { Observable, of as observableOf, Subscription } from 'rxjs';
import { map, filter } from 'rxjs/operators';
import { filter, map } from 'rxjs/operators';
import { Component, OnInit } from '@angular/core';
import { RouterReducerState } from '@ngrx/router-store';
import { select, Store } from '@ngrx/store';
@@ -9,13 +9,9 @@ import { fadeInOut, fadeOut } from '../animations/fade';
import { HostWindowService } from '../host-window.service';
import { AppState, routerStateSelector } from '../../app.reducer';
import { isNotUndefined } from '../empty.util';
import {
getAuthenticatedUser,
isAuthenticated,
isAuthenticationLoading
} from '../../core/auth/selectors';
import { getAuthenticatedUser, isAuthenticated, isAuthenticationLoading } from '../../core/auth/selectors';
import { EPerson } from '../../core/eperson/models/eperson.model';
import { AuthService, LOGIN_ROUTE, LOGOUT_ROUTE } from '../../core/auth/auth.service';
import { LOGIN_ROUTE, LOGOUT_ROUTE } from '../../core/auth/auth.service';
@Component({
selector: 'ds-auth-nav-menu',
@@ -45,8 +41,7 @@ export class AuthNavMenuComponent implements OnInit {
public sub: Subscription;
constructor(private store: Store<AppState>,
private windowService: HostWindowService,
private authService: AuthService
private windowService: HostWindowService
) {
this.isXsOrSm$ = this.windowService.isXsOrSm();
}
@@ -63,14 +58,9 @@ export class AuthNavMenuComponent implements OnInit {
this.showAuth = this.store.pipe(
select(routerStateSelector),
filter((router: RouterReducerState) => isNotUndefined(router) && isNotUndefined(router.state)),
map((router: RouterReducerState) => {
const url = router.state.url;
const show = !router.state.url.startsWith(LOGIN_ROUTE) && !router.state.url.startsWith(LOGOUT_ROUTE);
if (show) {
this.authService.setRedirectUrl(url);
}
return show;
})
map((router: RouterReducerState) => (!router.state.url.startsWith(LOGIN_ROUTE)
&& !router.state.url.startsWith(LOGOUT_ROUTE))
)
);
}
}