Skip to main content

Overview

The Navbar component provides the primary navigation structure for ScreenPulse, featuring responsive design, authentication state management, and dynamic menu toggling. Location: src/app/layout/navbar/navbar.component.ts

Key Features

  • Authentication Integration: Displays different UI based on login status
  • Responsive Design: Mobile menu with hamburger toggle
  • OnPush Change Detection: Optimized performance
  • Reactive State Management: Uses RxJS observables for user data

Component Structure

@Component({
  selector: 'app-navbar',
  templateUrl: './navbar.component.html',
  styleUrls: ['./navbar.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class NavbarComponent {
  expanded = false;
  readonly userData$ : Observable<UserSessionData> = combineLatest({
    email: this.authService.getUserMailObservable(),
    isLoggedIn: this.authService.isLoggedInObservable() 
  });

  constructor(
    private authService: AuthService,
    private router: Router
  ) { }

  logOut() {
    this.authService.logOut();
    this.router.navigate(['']);
  }

  toggleMenu() {
    this.expanded = !this.expanded;
  }
}

Properties

expanded
boolean
default:"false"
Controls the mobile menu visibility state
userData$
Observable<UserSessionData>
Observable combining user email and authentication status from AuthService

Methods

logOut()

Logs out the current user and navigates to the home page.
logOut() {
  this.authService.logOut();
  this.router.navigate(['']);
}

toggleMenu()

Toggles the mobile menu expansion state.
toggleMenu() {
  this.expanded = !this.expanded;
}
The navbar provides two main navigation routes:
  • Search (/): Main search page with exact route matching
  • Favorites (/favorites): User’s saved favorites collection

Authentication States

Not Logged In

  • Displays “Join us!” button linking to registration
  • Shows login icon button

Logged In

  • Displays welcome message with user email
  • Shows logout button
  • Enables access to all navigation links

Responsive Behavior

The navbar adapts to screen size:
  • Desktop: Shows all links inline with authentication controls
  • Mobile: Hamburger menu button reveals expanded drawer with navigation links

Dependencies

  • @angular/material/toolbar: Material toolbar component
  • @angular/material/icon: Material icons
  • AuthService: Manages authentication state
  • Router: Handles navigation

Build docs developers (and LLMs) love