Skip to content
Snippets Groups Projects
Commit 81831ee8 authored by Hugo BAYOUD's avatar Hugo BAYOUD
Browse files

Merge branch '1-front-creer-la-page-choix-des-bars' into 'master'

Resolve "[FRONT] Créer la page : choix des bars"

Closes #1

See merge request !1
parents 00914f01 f306d554
No related branches found
No related tags found
1 merge request!1Resolve "[FRONT] Créer la page : choix des bars"
...@@ -15,7 +15,7 @@ import { HttpErrorResponse } from "@angular/common/http"; ...@@ -15,7 +15,7 @@ import { HttpErrorResponse } from "@angular/common/http";
@Injectable() @Injectable()
export class AuthEffects { export class AuthEffects {
private subscription: Subscription; private subscription: Subscription = null;
constructor( constructor(
private actions$: Actions, private actions$: Actions,
...@@ -52,7 +52,6 @@ export class AuthEffects { ...@@ -52,7 +52,6 @@ export class AuthEffects {
exhaustMap((credentials: { email: string, password: string}) => exhaustMap((credentials: { email: string, password: string}) =>
this.authService.signin(credentials).pipe( this.authService.signin(credentials).pipe(
map((token: string) => { map((token: string) => {
console.log('try signinsuccess');
return new SigninSuccess(token) return new SigninSuccess(token)
}), }),
catchError((error: HttpErrorResponse) => { catchError((error: HttpErrorResponse) => {
...@@ -79,16 +78,16 @@ export class AuthEffects { ...@@ -79,16 +78,16 @@ export class AuthEffects {
map((action: SigninSuccess) => action.payload), map((action: SigninSuccess) => action.payload),
tap((token: string) => { tap((token: string) => {
localStorage.setItem('jwt', token); localStorage.setItem('jwt', token);
if (!this.subscription) { if (this.subscription === null) {
this.subscription = this.authService.initRefreshToken().subscribe(); this.subscription = this.authService.initRefreshToken().subscribe();
this.router.navigate(['/profile']); this.router.navigate(['/profile']);
} }
}), }),
); );
// Si on a pas de token, on a pas demander un refresh_token au back_end. // Si on a pas de token, on ne va pas demandé un refresh_token au back_end.
// On utilise donc le store dans l'effet pour vérifier (withLatestFrom) // On utilise donc le store dans l'effet pour le vérifier (withLatestFrom)
@Effect() @Effect()
tryRefreshToken$ = this.actions$.pipe( tryRefreshToken$ = this.actions$.pipe(
ofType(AuthActionsTypes.TRY_REFRESH_TOKEN), ofType(AuthActionsTypes.TRY_REFRESH_TOKEN),
...@@ -100,6 +99,7 @@ export class AuthEffects { ...@@ -100,6 +99,7 @@ export class AuthEffects {
catchError((err: any) => { catchError((err: any) => {
if(this.subscription) { if(this.subscription) {
this.subscription.unsubscribe(); this.subscription.unsubscribe();
this.subscription = null;
} }
localStorage.removeItem('jwt'); localStorage.removeItem('jwt');
......
import { Actions, createEffect, ofType } from "@ngrx/effects";
import { Injectable } from "@angular/core";
import { catchError, map, mergeMap } from "rxjs/operators";
import { EMPTY, of } from "rxjs";
import { BarActionsTypes, FetchBarsFailed, FetchBarsSuccess } from "../actions/bar.actions";
import { BarService } from "../../services/bar.service";
import { Bar } from "../../models/bar.model";
@Injectable()
export class BarEffects {
constructor(
private actions$: Actions,
private barService: BarService
) {}
loadBars$ = createEffect(() => this.actions$.pipe(
ofType(BarActionsTypes.FETCH_BARS),
mergeMap(() => this.barService.getAll()
.pipe(
map((bars: Bar[]) => (new FetchBarsSuccess(bars))),
catchError(() => of(new FetchBarsFailed('failed fetching all bars')))
))
));
}
\ No newline at end of file
import { ActionReducerMap } from "@ngrx/store"; import { ActionReducerMap } from "@ngrx/store";
import { authReducer, AuthState } from "./reducers/auth.reducers"; import { authReducer, AuthState } from "./reducers/auth.reducers";
import { barReducer, BarState } from "./reducers/bar.reducers";
export interface State { export interface State {
auth: AuthState; auth: AuthState;
bars: BarState;
} }
export const reducersMap: ActionReducerMap<State> = { export const reducersMap: ActionReducerMap<State> = {
auth: authReducer auth: authReducer,
bars: barReducer
}; };
\ No newline at end of file
import { Bar } from "../../models/bar.model";
import { BarsActions, BarActionsTypes } from "../actions/bar.actions";
export interface BarState {
bars: Bar[];
currentBar: Bar;
error: string;
}
const defaultBarState = {
bars: [],
currentBar: null,
error: '',
}
export function barReducer(state: BarState = defaultBarState, action: BarsActions): BarState {
switch (action.type) {
case BarActionsTypes.FETCH_BARS_SUCCESS: {
return {
...state,
bars: action.payload
};
}
case BarActionsTypes.FETCH_BARS_FAILED: {
return {
...state,
error: action.payload
};
}
}
return state;
}
\ No newline at end of file
import { createFeatureSelector, createSelector } from "@ngrx/store";
import { BarState } from "../reducers/bar.reducers";
export const baseSelector = createFeatureSelector('bars');
export const allBarsSelector = createSelector(baseSelector, (barState: BarState) => barState?.bars);
export const currentBarSelector = createSelector(baseSelector, (barState: BarState) => barState?.currentBar);
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
@import '~@angular/material/prebuilt-themes/deeppurple-amber.css'; @import '~@angular/material/prebuilt-themes/deeppurple-amber.css';
html, body { height: 100%; } html, body { height: 100%; }
body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; background-color: #f1f1f1; text-align: center;} body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; background-color: #f1f1f1; text-align: center; color: #222222}
.link { .link {
outline: 0; outline: 0;
...@@ -20,11 +20,17 @@ body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; background- ...@@ -20,11 +20,17 @@ body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; background-
.column-container { .column-container {
flex-direction: column; flex-flow: column nowrap;
padding: 5px;
}
.row-container {
display: flex;
flex-flow: row nowrap;
padding: 5px; padding: 5px;
} }
.column-container > * { .column-container > *, .row-container > * {
margin: 5px; margin: 5px;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment