From b54060fe06a1f83a22c60aa33ecb9d3c49044645 Mon Sep 17 00:00:00 2001 From: Chneemann Date: Wed, 27 Mar 2024 10:48:19 +0100 Subject: [PATCH] clean code --- src/app/app.routes.ts | 1 + .../contacts/contacts.component.html | 23 ++++++-- .../contacts/contacts.component.scss | 10 ++++ .../components/contacts/contacts.component.ts | 56 ++++++++++++------- 4 files changed, 65 insertions(+), 25 deletions(-) diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts index afcb13d..c330fbb 100644 --- a/src/app/app.routes.ts +++ b/src/app/app.routes.ts @@ -13,6 +13,7 @@ export const routes: Routes = [ { path: 'add-task', component: AddTaskComponent }, { path: 'board', component: BoardComponent }, { path: 'contacts', component: ContactsComponent }, + { path: 'contacts/:id', component: ContactsComponent }, { path: 'help', component: HelpComponent }, { path: 'imprint', component: ImprintComponent }, { path: 'privacy-policy', component: PrivacyPolicyComponent }, diff --git a/src/app/components/contacts/contacts.component.html b/src/app/components/contacts/contacts.component.html index 47ba693..2a9c505 100644 --- a/src/app/components/contacts/contacts.component.html +++ b/src/app/components/contacts/contacts.component.html @@ -13,17 +13,26 @@
@for (count of usersByFirstLetter[sortLetter]; track usersByFirstLetter; let index = $index) { -
+
- {{ displayInitials(usersByFirstLetter[sortLetter][index]) }} + {{ + displayUserDetails( + usersByFirstLetter[sortLetter][index], + "initials" + ) + }}
@@ -34,4 +43,10 @@ } }
+ @if (paramsId) { +
+

Contacts

+

{{ displayUserName(paramsId) }}

+
+ } diff --git a/src/app/components/contacts/contacts.component.scss b/src/app/components/contacts/contacts.component.scss index dbae9e3..875199b 100644 --- a/src/app/components/contacts/contacts.component.scss +++ b/src/app/components/contacts/contacts.component.scss @@ -102,6 +102,16 @@ section { } } +.right-frame { + position: absolute; + top: -64px; + left: 339px; + width: calc(100vw - 635px); + min-height: calc(100vh - 128px); + padding: 64px 48px 48px 48px; + box-shadow: 2px 0px 2px 0px rgba(0, 0, 0, 0.1); +} + @media screen and (max-width: 910px) { .left-frame { position: fixed; diff --git a/src/app/components/contacts/contacts.component.ts b/src/app/components/contacts/contacts.component.ts index 7026a8a..aad2b3e 100644 --- a/src/app/components/contacts/contacts.component.ts +++ b/src/app/components/contacts/contacts.component.ts @@ -2,11 +2,12 @@ import { Component } from '@angular/core'; import { UserService } from '../../services/user.service'; import { User } from '../../interfaces/user.interface'; import { CommonModule } from '@angular/common'; +import { ActivatedRoute, RouterLink } from '@angular/router'; @Component({ selector: 'app-contacts', standalone: true, - imports: [CommonModule], + imports: [CommonModule, RouterLink], templateUrl: './contacts.component.html', styleUrl: './contacts.component.scss', }) @@ -14,16 +15,38 @@ export class ContactsComponent { allUsers: User[] = []; usersFirstLetter: string[] = []; usersByFirstLetter: { [key: string]: string[] } = {}; + userMap: { [key: string]: User } = {}; + paramsId = ''; - constructor(private userService: UserService) { + constructor(private userService: UserService, private route: ActivatedRoute) { this.userService.subUserList().subscribe(() => { this.allUsers = this.loadAllUser(); + this.organizeUserData(); this.sortAllUsers(); this.sortUsersFirstLetter(); this.sortUsersByFirstLetter(); }); } + ngOnInit(): void { + this.routeUserId(); + } + + routeUserId() { + if (this.route.params.subscribe()) { + this.route.params.subscribe((params) => { + this.paramsId = params['id']; + }); + } + } + + organizeUserData() { + this.userMap = {}; + this.allUsers.forEach((user) => { + this.userMap[user.id] = user; + }); + } + loadAllUser(): User[] { // Without Guest return this.userService.allUsers.filter((user, index) => index !== 0); @@ -55,27 +78,18 @@ export class ContactsComponent { }); } - displayUser(firstLetter: string) { - return this.allUsers - .filter( - (user) => - user.firstName.charAt(0).toUpperCase() === firstLetter.toUpperCase() - ) - .map((user) => user.firstName); - } - displayUserName(id: string) { - let currentUser = this.allUsers.filter((user) => user.id === id); - return currentUser[0].firstName + ', ' + currentUser[0].lastName; + if (this.userMap[id]) { + return this.userMap[id].firstName + ', ' + this.userMap[id].lastName; + } + return ''; } - displayInitials(id: string) { - let currentUser = this.allUsers.filter((user) => user.id === id); - return currentUser[0].initials; - } - - displayInitialsColor(id: string) { - let currentUser = this.allUsers.filter((user) => user.id === id); - return currentUser[0].color; + displayUserDetails(id: string, query: keyof User) { + if (this.userMap[id]) { + const user = this.userMap[id]; + return user[query]; + } + return ''; } }