Skip to content

Commit

Permalink
feat: remove required login
Browse files Browse the repository at this point in the history
  • Loading branch information
69pmb committed Oct 25, 2023
1 parent d58de20 commit 4b06c78
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 31 deletions.
6 changes: 0 additions & 6 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,34 @@ const routes: Routes = [
import('./application-modules/dashboard/dashboard.module').then(
m => m.DashboardModule
),
canActivate: [AuthGard],
},
{
path: 'movie',
loadChildren: () =>
import('./application-modules/movie-detail/movie-detail.module').then(
m => m.MovieDetailModule
),
canActivate: [AuthGard],
},
{
path: 'serie',
loadChildren: () =>
import('./application-modules/serie-detail/serie-detail.module').then(
m => m.SerieDetailModule
),
canActivate: [AuthGard],
},
{
path: 'person',
loadChildren: () =>
import('./application-modules/person-detail/person-detail.module').then(
m => m.PersonDetailModule
),
canActivate: [AuthGard],
},
{
path: 'release',
loadChildren: () =>
import('./application-modules/release/release.module').then(
m => m.ReleaseModule
),
canActivate: [AuthGard],
},
{
path: 'datas',
Expand All @@ -58,7 +53,6 @@ const routes: Routes = [
import('./application-modules/discover/discover.module').then(
m => m.DiscoverModule
),
canActivate: [AuthGard],
},
{
path: 'tags',
Expand Down
30 changes: 23 additions & 7 deletions src/app/shared/components/menu/menu.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ng-container *ngIf="isLogged$ | async">
<ng-container *ngIf="isNotLoginPage$ | async">
<mat-toolbar class="toolbar" *ngIf="visible">
<button class="btn btn-light" (click)="sidenav.toggle()">
<fa-icon [icon]="faBars"></fa-icon>
Expand All @@ -18,16 +18,30 @@
[disableClose]="false"
autoFocus="false"
[mode]="mobileQuery.matches ? 'over' : 'push'"
*ngIf="isLogged$ | async"
*ngIf="isNotLoginPage$ | async"
>
<mat-nav-list class="nav-list" (click)="sidenav.close()">
<mat-nav-list
class="nav-list"
(click)="sidenav.close()"
*ngIf="{user: auth.user$ | async} as context"
>
<a mat-list-item appOpenLink url="/dashboard" label="nav_bar.dashboard">
<fa-icon [icon]="faHome"></fa-icon>
{{ 'nav_bar.dashboard' | translate }}
</a>
<a mat-list-item appOpenLink url="login/profile" label="nav_bar.profile">
<a mat-list-item routerLink="/login/connect" *ngIf="!context.user">
<fa-icon [icon]="faSignInAlt"></fa-icon>
{{ 'nav_bar.login' | translate }}
</a>
<a
mat-list-item
appOpenLink
url="login/profile"
label="nav_bar.profile"
*ngIf="context.user"
>
<fa-icon [icon]="faUser"></fa-icon>
{{ 'nav_bar.profile' | translate }} ({{ user?.name }})
{{ 'nav_bar.profile' | translate }} ({{ context.user?.name }})
</a>
<a mat-list-item appOpenLink url="/datas/movies" label="nav_bar.movies">
<fa-icon [icon]="faBookmark"></fa-icon>
Expand All @@ -49,11 +63,13 @@
<fa-icon [icon]="faAtom"></fa-icon>
{{ 'nav_bar.discover' | translate }}
</a>
<a mat-list-item (click)="logout()">
<a mat-list-item (click)="logout()" *ngIf="context.user">
<fa-icon [icon]="faPowerOff"></fa-icon>
{{ 'nav_bar.logout' | translate }}
</a>
<app-dropdown-language [userLang]="user?.lang"></app-dropdown-language>
<app-dropdown-language
[userLang]="context.user?.lang"
></app-dropdown-language>
</mat-nav-list>
</mat-sidenav>
<mat-sidenav-content #content class="sidenav-content">
Expand Down
22 changes: 9 additions & 13 deletions src/app/shared/components/menu/menu.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Router} from '@angular/router';
import {NavigationEnd, Router} from '@angular/router';
import {
Component,
OnInit,
Expand All @@ -8,7 +8,7 @@ import {
ViewChild,
ElementRef,
} from '@angular/core';
import {BehaviorSubject, Subscription} from 'rxjs';
import {Subscription} from 'rxjs';
import {
faUser,
faBars,
Expand All @@ -18,6 +18,7 @@ import {
faBoxOpen,
faBookmark,
faTags,
faSignInAlt,
} from '@fortawesome/free-solid-svg-icons';
import {MediaMatcher} from '@angular/cdk/layout';
import {MatSidenav, MatSidenavContent} from '@angular/material/sidenav';
Expand All @@ -27,6 +28,7 @@ import {Constants} from './../../../constant/constants';
import {AuthService} from '../../../service/auth.service';
import {User} from '../../../model/user';
import {MenuService} from '../../../service/menu.service';
import {filter, map} from 'rxjs/operators';

@Component({
selector: 'app-menu',
Expand All @@ -36,9 +38,12 @@ import {MenuService} from '../../../service/menu.service';
export class MenuComponent implements OnInit, OnDestroy {
mobileQuery: MediaQueryList;
user!: User;
isLogged$ = new BehaviorSubject<boolean>(false);
visible!: boolean;
subs: Subscription[] = [];
isNotLoginPage$ = this.router.events.pipe(
filter((e): e is NavigationEnd => e instanceof NavigationEnd),
map(e => !e.url.includes('login'))
);

faUser = faUser;
faBars = faBars;
Expand All @@ -48,6 +53,7 @@ export class MenuComponent implements OnInit, OnDestroy {
faHome = faHome;
faBoxOpen = faBoxOpen;
faPowerOff = faPowerOff;
faSignInAlt = faSignInAlt;

private _mobileQueryListener: () => void;
@ViewChild('sidenav', {static: false}) sidenav!: MatSidenav;
Expand All @@ -71,16 +77,6 @@ export class MenuComponent implements OnInit, OnDestroy {
}

ngOnInit(): void {
this.subs.push(
this.auth.user$.subscribe(user => {
if (user) {
this.user = user;
this.isLogged$.next(true);
} else {
this.isLogged$.next(false);
}
})
);
this.subs.push(
this.menuService.visible$.subscribe(visible => {
this.visible = visible;
Expand Down
20 changes: 15 additions & 5 deletions src/app/shared/directives/add-collection.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {DetailConfig} from '../../model/model';
import {MyTagsService} from '../../service/my-tags.service';
import {SerieService} from '../../service/serie.service';
import {MovieService} from '../../service/movie.service';
import {AuthService} from '../../service/auth.service';
import {Router} from '@angular/router';

@Directive({
selector: '[appAddCollection]',
Expand Down Expand Up @@ -54,11 +56,17 @@ export class AddCollectionDirective<T extends Data>
faTrash = faTrash;

@HostListener('click', ['$event']) onClick(): void {
if (!this.isAlreadyAdded) {
this.add();
} else {
this.remove();
}
this.auth.isAuthenticated().then(isAuth => {
if (!isAuth) {
this.router.navigate(['/login']);
} else {
if (!this.isAlreadyAdded) {
this.add();
} else {
this.remove();
}
}
});
}

constructor(
Expand All @@ -68,6 +76,8 @@ export class AddCollectionDirective<T extends Data>
private myTagsService: MyTagsService,
private translate: TranslateService,
private vcRef: ViewContainerRef,
private router: Router,
private auth: AuthService,
private el: ElementRef,
private cfr: ComponentFactoryResolver,
private render: Renderer2
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"playing": "Now Playing",
"profile": "My Profile",
"logout": "Log Out",
"login": "Log In",
"discover": "Discover",
"change_language": "Change Language",
"tags": "My Tags"
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"playing": "À l'Affiche",
"profile": "Mon Profil",
"logout": "Déconnexion",
"login": "Se connecter",
"discover": "Explorer",
"change_language": "Changer de Langue",
"tags": "Mes Tags"
Expand Down

0 comments on commit 4b06c78

Please sign in to comment.