Skip to content

Commit

Permalink
fix: navigation to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
cocotime committed Sep 29, 2023
1 parent d11c0a0 commit ee5255d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
Spectator,
} from '@ngneat/spectator/jest';
import { ProjectMockFactory } from '@taiga/data';
import { Subject } from 'rxjs';
import { Subject, of } from 'rxjs';
import { LocalStorageService } from '~/app/shared/local-storage/local-storage.service';
import { getTranslocoModule } from '~/app/transloco/transloco-testing.module';
import { ProjectNavigationComponent } from './project-feature-navigation.component';
Expand Down Expand Up @@ -57,6 +57,9 @@ describe('ProjectNavigationComponent', () => {
settings: true,
},
},
data: of({
settings: true,
}),
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,24 @@ import {
ElementRef,
HostBinding,
HostListener,
inject,
Input,
OnInit,
DestroyRef,
} from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import {
ActivatedRoute,
ActivatedRouteSnapshot,
Router,
} from '@angular/router';
import { RxState } from '@rx-angular/state';
import { Project } from '@taiga/data';
import { Subject } from 'rxjs';
import { LocalStorageService } from '~/app/shared/local-storage/local-storage.service';
import { ProjectNavigationSettingsComponent } from './components/project-navigation-settings/project-navigation-settings.component';
import { CommonModule } from '@angular/common';
import { ProjectNavigationMenuComponent } from './components/project-navigation-menu/project-navigation-menu.component';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';

const collapseMenuAnimation = '200ms ease-out';
const openMenuAnimation = '200ms ease-in';
Expand Down Expand Up @@ -199,6 +206,7 @@ export class ProjectNavigationComponent implements OnInit, AfterViewInit {
public showProjectSettings = false;
public settingsAnimationInProgress = false;
public animationEvents$ = new Subject<AnimationEvent>();
private destroyRef = inject(DestroyRef);

constructor(
private el: ElementRef,
Expand All @@ -209,7 +217,7 @@ export class ProjectNavigationComponent implements OnInit, AfterViewInit {

public ngOnInit() {
this.collapsed = !!LocalStorageService.get('projectnav-collapsed');
this.router.events.subscribe(() => {
this.route.data.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => {
this.showProjectSettings = this.isSettings();
});
this.showProjectSettings = this.isSettings();
Expand All @@ -221,7 +229,14 @@ export class ProjectNavigationComponent implements OnInit, AfterViewInit {
}

public isSettings() {
return !!this.route.snapshot.data.settings;
const getActiveRoute = (
route: ActivatedRouteSnapshot
): ActivatedRouteSnapshot => {
return route.firstChild ? getActiveRoute(route.firstChild) : route;
};
const active = getActiveRoute(this.route.snapshot);

return !!active.data.settings;
}

public calcBlockSize() {
Expand Down

0 comments on commit ee5255d

Please sign in to comment.