import { ChangeDetectionStrategy, Component, inject } from '@angular/core'; import { toSignal } from '@angular/core/rxjs-interop'; import { NavigationEnd, Router, RouterLink, RouterLinkActive, RouterOutlet, } from '@angular/router'; import { filter, map } from 'rxjs'; import { AuthFacade } from '@task-stream/web/identity/application'; import { UserMenuComponent } from '@task-stream/web/identity/presenters'; import { PiIconButtonComponent } from '@pi/ui'; import { AppShellComponent } from '@task-stream/web/shared/ui'; import { CommandPalette, NotificationsBell, } from '@task-stream/web/tracker/presenters'; @Component({ selector: 'ts-root', changeDetection: ChangeDetectionStrategy.OnPush, imports: [ RouterOutlet, RouterLink, RouterLinkActive, AppShellComponent, UserMenuComponent, NotificationsBell, CommandPalette, PiIconButtonComponent, ], styles: ` /* The palette's button, still: same box, so nothing moves when it loads. */ .ts-shell-search { display: inline-flex; gap: 0.375rem; align-items: center; border: 0; background: none; font: inherit; cursor: pointer; kbd { font-size: 0.6875rem; opacity: 0.7; } } `, template: ` @if (auth.isAuthenticated()) { Proyectos } @if (auth.isAuthenticated()) { Cartera } Explorar @if (auth.isAuthenticated()) { @defer (on idle; on interaction) { } @placeholder { } @defer (on idle; on interaction) { } @placeholder { } } @else if (auth.settled() && !onLogin()) { Iniciar sesión } `, }) export class App { protected readonly auth = inject(AuthFacade); private readonly router = inject(Router); /** The login page has its own form: no "Iniciar sesión" button there. */ protected readonly onLogin = toSignal( this.router.events.pipe( filter((event) => event instanceof NavigationEnd), map(() => this.router.url.startsWith('/login')), ), { initialValue: false }, ); }