Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

1.7 KB
Raw Blame
import { Component, inject, OnDestroy } from '@angular/core'
import { Subscription } from 'rxjs'
import { UserType } from '../../applications/users/interfaces/user.interface'
import { USER_ONLINE_STATUS_LIST } from '../../applications/users/user.constants'
import { StoreService } from '../../store/store.service'
import { BreadcrumbComponent } from '../breadcrumb/breadcrumb.component'
import { TAB_MENU } from '../layout.interfaces'
import { LayoutService } from '../layout.service'
import { NavbarSearchComponent } from '../../applications/search/navbar/navbar-search.component'
import { NavbarSearchService } from './services/navbar-search.service'

@Component({
  selector: 'app-navbar',
  templateUrl: 'navbar.component.html',
  imports: [BreadcrumbComponent, NavbarSearchComponent]
})
export class NavBarComponent implements OnDestroy {
  protected readonly allOnlineStatus = USER_ONLINE_STATUS_LIST
  protected readonly navbarSearch = inject(NavbarSearchService)
  protected leftSideBarIsOpen = true
  protected user: UserType
  protected userAvatar: string = null
  private readonly layout = inject(LayoutService)
  private readonly store = inject(StoreService)
  private subscriptions: Subscription[] = []

  constructor() {
    this.subscriptions.push(this.store.user.subscribe((user: UserType) => (this.user = user)))
    this.subscriptions.push(this.store.userAvatarUrl.subscribe((avatarUrl) => (this.userAvatar = avatarUrl)))
    this.subscriptions.push(this.layout.leftSideBarIsOpen.subscribe((isOpen) => (this.leftSideBarIsOpen = isOpen)))
  }

  ngOnDestroy() {
    this.subscriptions.forEach((s) => s.unsubscribe())
  }

  openSidebarUser() {
    this.layout.showRSideBarTab(TAB_MENU.PROFILE)
  }

  toggleLeftSideBar() {
    this.layout.toggleLSideBar()
  }
}