WIP
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
import { Component, OnInit, OnDestroy, HostListener } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Router, NavigationEnd, RouterModule, RouterLink, RouterLinkActive } from '@angular/router';
|
||||
import { RouterOutlet } from '@angular/router';
|
||||
import { AuthService, User } from '../../shared/services/auth.service';
|
||||
import { Subject, takeUntil, filter } from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'app-user-portal',
|
||||
standalone: true,
|
||||
imports: [
|
||||
CommonModule,
|
||||
RouterModule,
|
||||
RouterLink,
|
||||
RouterLinkActive,
|
||||
RouterOutlet
|
||||
],
|
||||
templateUrl: './user-portal.component.html',
|
||||
styleUrls: ['./user-portal.component.scss']
|
||||
})
|
||||
export class UserPortalComponent implements OnInit, OnDestroy {
|
||||
sidebarCollapsed = false;
|
||||
isMobile = false;
|
||||
currentUser: User | null = null;
|
||||
currentPageTitle = 'Dashboard';
|
||||
unreadMessages = 3;
|
||||
unreadNotifications = 2;
|
||||
|
||||
private destroy$ = new Subject<void>();
|
||||
|
||||
constructor(
|
||||
private authService: AuthService,
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.checkScreenSize();
|
||||
this.setupUserSubscription();
|
||||
this.setupRouteSubscription();
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
@HostListener('window:resize', ['$event'])
|
||||
onResize(event: any): void {
|
||||
this.checkScreenSize();
|
||||
}
|
||||
|
||||
private checkScreenSize(): void {
|
||||
this.isMobile = window.innerWidth <= 768;
|
||||
if (this.isMobile) {
|
||||
this.sidebarCollapsed = true;
|
||||
} else {
|
||||
// On desktop, start with sidebar expanded
|
||||
this.sidebarCollapsed = false;
|
||||
}
|
||||
}
|
||||
|
||||
private setupUserSubscription(): void {
|
||||
this.authService.currentUser$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe(user => {
|
||||
this.currentUser = user;
|
||||
});
|
||||
}
|
||||
|
||||
private setupRouteSubscription(): void {
|
||||
this.router.events
|
||||
.pipe(
|
||||
filter(event => event instanceof NavigationEnd),
|
||||
takeUntil(this.destroy$)
|
||||
)
|
||||
.subscribe(() => {
|
||||
this.updatePageTitle();
|
||||
});
|
||||
}
|
||||
|
||||
private updatePageTitle(): void {
|
||||
const url = this.router.url;
|
||||
const segments = url.split('/').filter(segment => segment);
|
||||
|
||||
if (segments.length >= 2) {
|
||||
const page = segments[1];
|
||||
this.currentPageTitle = this.getPageTitle(page);
|
||||
} else {
|
||||
this.currentPageTitle = 'Dashboard';
|
||||
}
|
||||
}
|
||||
|
||||
private getPageTitle(page: string): string {
|
||||
const titles: { [key: string]: string } = {
|
||||
'dashboard': 'Dashboard',
|
||||
'transactions': 'Escrow Transactions',
|
||||
'tasks': 'Tasks & Todos',
|
||||
'contacts': 'Contacts',
|
||||
'documents': 'Documents',
|
||||
'messages': 'Messages',
|
||||
'settings': 'Settings'
|
||||
};
|
||||
|
||||
return titles[page] || 'Dashboard';
|
||||
}
|
||||
|
||||
toggleSidebar(): void {
|
||||
this.sidebarCollapsed = !this.sidebarCollapsed;
|
||||
}
|
||||
|
||||
get mainContentClass(): string {
|
||||
return this.sidebarCollapsed ? 'main-content sidebar-collapsed' : 'main-content';
|
||||
}
|
||||
|
||||
onSidebarOverlayClick(): void {
|
||||
if (this.isMobile && !this.sidebarCollapsed) {
|
||||
this.sidebarCollapsed = true;
|
||||
}
|
||||
}
|
||||
|
||||
onNavigationClick(): void {
|
||||
if (this.isMobile) {
|
||||
this.sidebarCollapsed = true;
|
||||
}
|
||||
}
|
||||
|
||||
logout(): void {
|
||||
this.authService.logout();
|
||||
this.router.navigate(['/login']);
|
||||
}
|
||||
|
||||
getDisplayName(): string {
|
||||
if (this.currentUser) {
|
||||
const fullName = `${this.currentUser.firstName} ${this.currentUser.lastName}`.trim();
|
||||
return fullName || this.currentUser.email;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user