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

create bars component and bars service in order to fetch all bars in mongoDB

parent bc6e52b6
No related branches found
No related tags found
1 merge request!1Resolve "[FRONT] Créer la page : choix des bars"
...@@ -18,13 +18,14 @@ import { APP_ROUTING } from './app.routing'; ...@@ -18,13 +18,14 @@ import { APP_ROUTING } from './app.routing';
import { StoreModule } from '@ngrx/store'; import { StoreModule } from '@ngrx/store';
import { EffectsModule } from '@ngrx/effects'; import { EffectsModule } from '@ngrx/effects';
import { StoreDevtoolsModule } from '@ngrx/store-devtools'; import { StoreDevtoolsModule } from '@ngrx/store-devtools';
// others
import { environment } from 'src/environments/environment'; import { environment } from 'src/environments/environment';
import { reducersMap } from './share/store'; import { reducersMap } from './share/store';
import { AuthEffects } from './share/store/effects/auth.effects'; import { AuthEffects } from './share/store/effects/auth.effects';
import { WelcomeComponent } from './components/welcome/welcome.component';
@NgModule({ @NgModule({
declarations: [AppComponent, WelcomeComponent], declarations: [AppComponent],
imports: [ imports: [
BrowserModule, BrowserModule,
BrowserAnimationsModule, BrowserAnimationsModule,
......
import { Route } from "@angular/router"; import { Route } from "@angular/router";
import { BarsComponent } from "./components/bars/bars.component";
import { SigninComponent } from "./components/signin/signin.component"; import { SigninComponent } from "./components/signin/signin.component";
import { SignupComponent } from "./components/signup/signup.component"; import { SignupComponent } from "./components/signup/signup.component";
import { WelcomeComponent } from "./components/welcome/welcome.component"; import { WelcomeComponent } from "./components/welcome/welcome.component";
...@@ -9,9 +10,9 @@ export const APP_ROUTING: Route[] = [ ...@@ -9,9 +10,9 @@ export const APP_ROUTING: Route[] = [
{ path: 'welcome', canActivate: [AlreadyLoggedInGuard], component: WelcomeComponent }, { path: 'welcome', canActivate: [AlreadyLoggedInGuard], component: WelcomeComponent },
{ path: 'photos', canActivate: [AuthGuard], loadChildren: () => import('./photos/photos.module').then(m => m.PhotosModule) }, { path: 'photos', canActivate: [AuthGuard], loadChildren: () => import('./photos/photos.module').then(m => m.PhotosModule) },
{ path: 'profile', canActivate: [AuthGuard], loadChildren: () => import('./profile/profile.module').then(m => m.ProfileModule) }, { path: 'profile', canActivate: [AuthGuard], loadChildren: () => import('./profile/profile.module').then(m => m.ProfileModule) },
// { path: 'bars', canActivate: [AuthGuard], loadChildren: () => import('./bars/bars.module').then(m => m.BarsModule) }, { path: 'bars', canActivate: [AuthGuard], component: BarsComponent },
{ path: 'signup', canActivate: [AlreadyLoggedInGuard], component: SignupComponent }, { path: 'signup', canActivate: [AlreadyLoggedInGuard], component: SignupComponent },
{ path: 'signin', canActivate: [AlreadyLoggedInGuard], component: SigninComponent }, { path: 'signin', canActivate: [AlreadyLoggedInGuard], component: SigninComponent },
{ path: '', redirectTo: 'welcome', pathMatch: 'full' }, { path: '', redirectTo: '', pathMatch: 'full' },
{ path: '**', redirectTo: 'welcome', pathMatch: 'full' }, { path: '**', redirectTo: '', pathMatch: 'full' },
]; ];
\ No newline at end of file
<p>bars works!</p>
<p>
<button mat-raised-button routerLink="/profile" color="primary">profile</button>
<button mat-raised-button routerLink="/photos" color="accent">photos</button>
</p>
\ No newline at end of file
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-bars',
templateUrl: './bars.component.html',
styleUrls: ['./bars.component.css']
})
export class BarsComponent implements OnInit {
constructor() {}
ngOnInit(): void {}
}
...@@ -22,8 +22,6 @@ export class PhotosComponent implements OnInit { ...@@ -22,8 +22,6 @@ export class PhotosComponent implements OnInit {
private notificationService: NotificationService private notificationService: NotificationService
) { ) {
this.swUpdate.available.subscribe((version) => { this.swUpdate.available.subscribe((version) => {
console.log(version);
if (version) { if (version) {
this.swUpdate.activateUpdate().then(() => { this.swUpdate.activateUpdate().then(() => {
window.location.reload(); window.location.reload();
......
<p>profile works!</p> <p>profile works!</p>
\ No newline at end of file <p>
<button mat-raised-button routerLink="/bars" color="primary">Liste des bars</button>
<button mat-raised-button routerLink="/photos" color="accent">photos</button>
</p>
\ No newline at end of file
...@@ -19,7 +19,6 @@ export class ProfileComponent implements OnInit { ...@@ -19,7 +19,6 @@ export class ProfileComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
this.currentUser$ = this.store.pipe(select(userAuthSelector)); this.currentUser$ = this.store.pipe(select(userAuthSelector));
this.store.dispatch(new TryFetchCurrentUser()); this.store.dispatch(new TryFetchCurrentUser());
console.log('finishing init');
} }
} }
<mat-toolbar *ngIf="isLoggedIn$ | async" color="primary" fxLayoutGap="15px"> <mat-toolbar *ngIf="isLoggedIn$ | async" color="primary" fxLayoutGap="15px">
<span routerLink="/">Mon logo</span> <span routerLink="/welcome">Mon logo</span>
<!-- <span *ngIf="!(isLoggedIn$ | async)" fxLayoutGap="15px" fxLayout="row" fxLayoutAlign="center center"> <!-- <span *ngIf="!(isLoggedIn$ | async)" fxLayoutGap="15px" fxLayout="row" fxLayoutAlign="center center">
<mat-icon class="link" routerLink="/signin">login</mat-icon> <mat-icon class="link" routerLink="/signin">login</mat-icon>
<mat-icon class="link" routerLink="/signup">launch</mat-icon> <mat-icon class="link" routerLink="/signup">launch</mat-icon>
......
...@@ -21,10 +21,14 @@ import { TopbarComponent } from '../components/topbar/topbar.component'; ...@@ -21,10 +21,14 @@ import { TopbarComponent } from '../components/topbar/topbar.component';
// Interceptors // Interceptors
import { AuthInterceptor } from '../interceptors/auth.interceptor'; import { AuthInterceptor } from '../interceptors/auth.interceptor';
import { ReactiveFormsModule } from '@angular/forms'; import { ReactiveFormsModule } from '@angular/forms';
import { WelcomeComponent } from 'src/app/components/welcome/welcome.component';
import { BarsComponent } from 'src/app/components/bars/bars.component';
const COMPONENTS = [ const COMPONENTS = [
SignupComponent, SignupComponent,
SigninComponent, SigninComponent,
WelcomeComponent,
BarsComponent,
TopbarComponent TopbarComponent
]; ];
......
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class BarsService {
constructor() { }
}
...@@ -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');
......
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