From c2412c0d2983ed4b3e4b839a83b08d2ecbcbd773 Mon Sep 17 00:00:00 2001 From: Hugo BAYOUD <hugo.bayoud@etu.uca.fr> Date: Wed, 24 Mar 2021 22:29:27 +0100 Subject: [PATCH] create bars component and bars service in order to fetch all bars in mongoDB --- src/app/app.module.ts | 5 +++-- src/app/app.routing.ts | 7 ++++--- src/app/components/bars/bars.component.css | 0 src/app/components/bars/bars.component.html | 5 +++++ src/app/components/bars/bars.component.ts | 14 ++++++++++++++ src/app/photos/photos.component.ts | 2 -- src/app/profile/profile.component.html | 6 +++++- src/app/profile/profile.component.ts | 1 - .../share/components/topbar/topbar.component.html | 2 +- src/app/share/modules/core.module.ts | 4 ++++ src/app/share/services/bars.service.ts | 9 +++++++++ src/app/share/store/effects/auth.effects.ts | 12 ++++++------ 12 files changed, 51 insertions(+), 16 deletions(-) create mode 100644 src/app/components/bars/bars.component.css create mode 100644 src/app/components/bars/bars.component.html create mode 100644 src/app/components/bars/bars.component.ts create mode 100644 src/app/share/services/bars.service.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index b83e94dc..d00e9c77 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -18,13 +18,14 @@ import { APP_ROUTING } from './app.routing'; import { StoreModule } from '@ngrx/store'; import { EffectsModule } from '@ngrx/effects'; import { StoreDevtoolsModule } from '@ngrx/store-devtools'; + +// others import { environment } from 'src/environments/environment'; import { reducersMap } from './share/store'; import { AuthEffects } from './share/store/effects/auth.effects'; -import { WelcomeComponent } from './components/welcome/welcome.component'; @NgModule({ - declarations: [AppComponent, WelcomeComponent], + declarations: [AppComponent], imports: [ BrowserModule, BrowserAnimationsModule, diff --git a/src/app/app.routing.ts b/src/app/app.routing.ts index c766de66..c19269af 100644 --- a/src/app/app.routing.ts +++ b/src/app/app.routing.ts @@ -1,4 +1,5 @@ import { Route } from "@angular/router"; +import { BarsComponent } from "./components/bars/bars.component"; import { SigninComponent } from "./components/signin/signin.component"; import { SignupComponent } from "./components/signup/signup.component"; import { WelcomeComponent } from "./components/welcome/welcome.component"; @@ -9,9 +10,9 @@ export const APP_ROUTING: Route[] = [ { path: 'welcome', canActivate: [AlreadyLoggedInGuard], component: WelcomeComponent }, { 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: '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: 'signin', canActivate: [AlreadyLoggedInGuard], component: SigninComponent }, - { path: '', redirectTo: 'welcome', pathMatch: 'full' }, - { path: '**', redirectTo: 'welcome', pathMatch: 'full' }, + { path: '', redirectTo: '', pathMatch: 'full' }, + { path: '**', redirectTo: '', pathMatch: 'full' }, ]; \ No newline at end of file diff --git a/src/app/components/bars/bars.component.css b/src/app/components/bars/bars.component.css new file mode 100644 index 00000000..e69de29b diff --git a/src/app/components/bars/bars.component.html b/src/app/components/bars/bars.component.html new file mode 100644 index 00000000..6c4e88db --- /dev/null +++ b/src/app/components/bars/bars.component.html @@ -0,0 +1,5 @@ +<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 diff --git a/src/app/components/bars/bars.component.ts b/src/app/components/bars/bars.component.ts new file mode 100644 index 00000000..9046c8da --- /dev/null +++ b/src/app/components/bars/bars.component.ts @@ -0,0 +1,14 @@ +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 {} + +} diff --git a/src/app/photos/photos.component.ts b/src/app/photos/photos.component.ts index 09dcdc27..501cb9c0 100644 --- a/src/app/photos/photos.component.ts +++ b/src/app/photos/photos.component.ts @@ -22,8 +22,6 @@ export class PhotosComponent implements OnInit { private notificationService: NotificationService ) { this.swUpdate.available.subscribe((version) => { - console.log(version); - if (version) { this.swUpdate.activateUpdate().then(() => { window.location.reload(); diff --git a/src/app/profile/profile.component.html b/src/app/profile/profile.component.html index cdfad31a..55873514 100644 --- a/src/app/profile/profile.component.html +++ b/src/app/profile/profile.component.html @@ -1 +1,5 @@ -<p>profile works!</p> \ No newline at end of file +<p>profile works!</p> +<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 diff --git a/src/app/profile/profile.component.ts b/src/app/profile/profile.component.ts index daad8f91..0a12a2d8 100644 --- a/src/app/profile/profile.component.ts +++ b/src/app/profile/profile.component.ts @@ -19,7 +19,6 @@ export class ProfileComponent implements OnInit { ngOnInit(): void { this.currentUser$ = this.store.pipe(select(userAuthSelector)); this.store.dispatch(new TryFetchCurrentUser()); - console.log('finishing init'); } } diff --git a/src/app/share/components/topbar/topbar.component.html b/src/app/share/components/topbar/topbar.component.html index 72b04a4b..8ab70b50 100644 --- a/src/app/share/components/topbar/topbar.component.html +++ b/src/app/share/components/topbar/topbar.component.html @@ -1,5 +1,5 @@ <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"> <mat-icon class="link" routerLink="/signin">login</mat-icon> <mat-icon class="link" routerLink="/signup">launch</mat-icon> diff --git a/src/app/share/modules/core.module.ts b/src/app/share/modules/core.module.ts index 08f0ffdd..887ac028 100644 --- a/src/app/share/modules/core.module.ts +++ b/src/app/share/modules/core.module.ts @@ -21,10 +21,14 @@ import { TopbarComponent } from '../components/topbar/topbar.component'; // Interceptors import { AuthInterceptor } from '../interceptors/auth.interceptor'; 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 = [ SignupComponent, SigninComponent, + WelcomeComponent, + BarsComponent, TopbarComponent ]; diff --git a/src/app/share/services/bars.service.ts b/src/app/share/services/bars.service.ts new file mode 100644 index 00000000..74ff23e2 --- /dev/null +++ b/src/app/share/services/bars.service.ts @@ -0,0 +1,9 @@ +import { Injectable } from '@angular/core'; + +@Injectable({ + providedIn: 'root' +}) +export class BarsService { + + constructor() { } +} diff --git a/src/app/share/store/effects/auth.effects.ts b/src/app/share/store/effects/auth.effects.ts index cc9fd709..90b9043c 100644 --- a/src/app/share/store/effects/auth.effects.ts +++ b/src/app/share/store/effects/auth.effects.ts @@ -15,7 +15,7 @@ import { HttpErrorResponse } from "@angular/common/http"; @Injectable() export class AuthEffects { - private subscription: Subscription; + private subscription: Subscription = null; constructor( private actions$: Actions, @@ -52,7 +52,6 @@ export class AuthEffects { exhaustMap((credentials: { email: string, password: string}) => this.authService.signin(credentials).pipe( map((token: string) => { - console.log('try signinsuccess'); return new SigninSuccess(token) }), catchError((error: HttpErrorResponse) => { @@ -79,16 +78,16 @@ export class AuthEffects { map((action: SigninSuccess) => action.payload), tap((token: string) => { localStorage.setItem('jwt', token); - - if (!this.subscription) { + + if (this.subscription === null) { this.subscription = this.authService.initRefreshToken().subscribe(); this.router.navigate(['/profile']); } }), ); - // Si on a pas de token, on a pas demander un refresh_token au back_end. - // On utilise donc le store dans l'effet pour vérifier (withLatestFrom) + // 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 le vérifier (withLatestFrom) @Effect() tryRefreshToken$ = this.actions$.pipe( ofType(AuthActionsTypes.TRY_REFRESH_TOKEN), @@ -100,6 +99,7 @@ export class AuthEffects { catchError((err: any) => { if(this.subscription) { this.subscription.unsubscribe(); + this.subscription = null; } localStorage.removeItem('jwt'); -- GitLab