diff --git a/package-lock.json b/package-lock.json index 62e1f19..93800ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22130,6 +22130,7 @@ "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.13.tgz", "integrity": "sha512-oWb1Z6mkHIskLzEJ/XWX0srkpkTQ7vaopMQkyaEIoq0fmtFVxOthb8cCxeT+p3ynTdkk/RZwbgG4brR5BeWECw==", "dev": true, + "hasInstallScript": true, "optional": true, "os": [ "darwin" diff --git a/src/app/modules/songs/song-list/song-list.component.ts b/src/app/modules/songs/song-list/song-list.component.ts index b88cfdc..5db9f8f 100644 --- a/src/app/modules/songs/song-list/song-list.component.ts +++ b/src/app/modules/songs/song-list/song-list.component.ts @@ -1,4 +1,4 @@ -import {Component, OnDestroy, OnInit} from '@angular/core'; +import {ChangeDetectionStrategy, Component, OnDestroy, OnInit} from '@angular/core'; import {SongService} from '../services/song.service'; import {Song} from '../services/song'; import {debounceTime, map} from 'rxjs/operators'; @@ -13,6 +13,7 @@ import {ScrollService} from '../../../services/scroll.service'; selector: 'app-songs', templateUrl: './song-list.component.html', styleUrls: ['./song-list.component.less'], + changeDetection: ChangeDetectionStrategy.OnPush, animations: [fade], }) export class SongListComponent implements OnInit, OnDestroy { diff --git a/src/app/modules/songs/song/song.component.less b/src/app/modules/songs/song/song.component.less index aa7feba..0e3f2fd 100644 --- a/src/app/modules/songs/song/song.component.less +++ b/src/app/modules/songs/song/song.component.less @@ -13,6 +13,7 @@ .detail { display: grid; + grid-gap: 10px; grid-template-columns: 1fr 1fr 1fr; font-style: italic; } diff --git a/src/app/services/user/role.directive.ts b/src/app/services/user/role.directive.ts index 1bae3ba..fc5a2d5 100644 --- a/src/app/services/user/role.directive.ts +++ b/src/app/services/user/role.directive.ts @@ -1,7 +1,8 @@ -import {Directive, ElementRef, Input, OnInit, TemplateRef, ViewContainerRef} from '@angular/core'; +import {ChangeDetectorRef, Directive, ElementRef, Input, OnInit, TemplateRef, ViewContainerRef} from '@angular/core'; import {roles} from './roles'; import {UserService} from './user.service'; import {User} from './user'; +import {combineLatest} from 'rxjs'; @Directive({ selector: '[appRole]', @@ -15,25 +16,26 @@ export class RoleDirective implements OnInit { private element: ElementRef, private templateRef: TemplateRef, private viewContainer: ViewContainerRef, - private userService: UserService + private userService: UserService, + private changeDetection: ChangeDetectorRef ) {} public ngOnInit(): void { - this.userService.user$.subscribe(user => { - this.currentUser = user; + combineLatest([this.userService.user$, this.userService.loggedIn$()]).subscribe(_ => { + this.currentUser = _[0]; + this.loggedIn = _[1]; this.updateView(); }); - this.userService.loggedIn$().subscribe(_ => { - this.loggedIn = !!_; - this.updateView(); - }); - this.updateView(); } + private currentViewState = false; private updateView() { - this.viewContainer.clear(); - if (this.loggedIn && this.checkPermission()) { - this.viewContainer.createEmbeddedView(this.templateRef); + const viewState = this.loggedIn && this.checkPermission(); + if (this.currentViewState !== viewState) { + if (!viewState) this.viewContainer.clear(); + if (viewState) this.viewContainer.createEmbeddedView(this.templateRef); + this.changeDetection.markForCheck(); + this.currentViewState = viewState; } } diff --git a/src/app/services/user/user.service.ts b/src/app/services/user/user.service.ts index 04ef7df..5bc7ff2 100644 --- a/src/app/services/user/user.service.ts +++ b/src/app/services/user/user.service.ts @@ -54,7 +54,7 @@ export class UserService { return aUser.user.uid; } - public loggedIn$: () => Observable = () => this.afAuth.authState; + public loggedIn$: () => Observable = () => this.afAuth.authState.pipe(map(_ => !!_)); public list$: () => Observable = (): Observable => this.db.col$('users');