- @if(user.status) {
+ @if(selectedUser.isOnline) {

} @else {

}
- {{ user.initials }}
+ {{ selectedUser.initials }}
- {{ user.firstName }}
- {{ user.lastName }}
- @if (user.id === firebaseService.getCurrentUserId()) {
+ {{ selectedUser.firstName }}
+ {{ selectedUser.lastName }}
+ @if (currentUser && selectedUser.id === currentUser.id) {
{{ "contacts.you" | translate }}
}
- @if(user.uId === "" || user.id === firebaseService.getCurrentUserId()) {
+ @if(selectedUser.isContactOnly || currentUser && selectedUser.id ===
+ currentUser.id) {

@@ -55,7 +55,8 @@
{{ "contacts.btnEdit0" | translate }}
- @if (user.id !== firebaseService.getCurrentUserId()) {
+ @if (selectedUser.isContactOnly || currentUser && selectedUser.id !==
+ currentUser.id) {
@@ -74,21 +75,21 @@
{{ "contacts.contactInfo" | translate }}
{{ "contacts.contactEmail" | translate }}
-
- {{ user.email }}
+
+ {{ selectedUser.email }}
{{ "contacts.contactPhone" | translate }}
- @if(user.phone === '') {
+ @if(selectedUser.phone === '') {
{{ "contacts.contactPhoneTxT" | translate }} } @else {
-
- {{ user.phone }}
+
+ {{ selectedUser.phone }}
- } @if(user.uId !== "") {
+ } @if(selectedUser.uId !== "") {
{{ "contacts.contactLastOnline" | translate }}
- @if(user.status) {
+ @if(selectedUser.isOnline) {
{{ "contacts.contactLastOnlineTxt" | translate }}
} @else {
-
{{ convertTimestamp(user.lastLogin) }}
+
{{ convertTimestamp(selectedUser.lastLogin) }}
} }
@@ -98,5 +99,5 @@
[deleteContact]="deleteContact"
[openEditDialog]="openEditDialog"
>
- }}
+ }
diff --git a/src/app/components/contacts/contact-detail/contact-detail.component.ts b/src/app/components/contacts/contact-detail/contact-detail.component.ts
index ff04c74..ece327e 100644
--- a/src/app/components/contacts/contact-detail/contact-detail.component.ts
+++ b/src/app/components/contacts/contact-detail/contact-detail.component.ts
@@ -4,6 +4,7 @@ import {
HostListener,
Input,
Output,
+ SimpleChanges,
} from '@angular/core';
import { CommonModule } from '@angular/common';
import { Router } from '@angular/router';
@@ -12,6 +13,9 @@ import { ContactNavComponent } from '../contact-nav/contact-nav.component';
import { FirebaseService } from '../../../services/firebase.service';
import { LanguageService } from '../../../services/language.service';
import { TranslateModule } from '@ngx-translate/core';
+import { UserService } from '../../../services/user.service';
+import { finalize } from 'rxjs';
+import { User } from '../../../interfaces/user.interface';
@Component({
selector: 'app-contact-detail',
@@ -21,34 +25,59 @@ import { TranslateModule } from '@ngx-translate/core';
styleUrl: './contact-detail.component.scss',
})
export class ContactDetailComponent {
- @Input() currentUserId: string | undefined;
+ @Input() selectedUserId: string | undefined;
+ @Input() currentUser: User | null = null;
@Output() closeContactEmitter = new EventEmitter
();
+ isLoading: boolean = false;
+ selectedUser: User | null = null;
+
constructor(
private router: Router,
public sharedService: SharedService,
public firebaseService: FirebaseService,
+ private userService: UserService,
private languageService: LanguageService
) {}
+ ngOnChanges(changes: SimpleChanges) {
+ if (
+ changes['selectedUserId'] !== undefined &&
+ changes['selectedUserId'].currentValue !== ''
+ ) {
+ this.loadUser();
+ } else {
+ this.selectedUser = null;
+ }
+ }
+
/**
* Closes the contact details view by resetting the current user id in the
* shared service and emitting the closeContactEmitter event.
*/
closeUserDetails() {
- this.sharedService.currentUserId = '';
this.closeContactEmitter.emit();
}
- /**
- * Checks if a user with the given user id exists in the database.
- * @param userId the id of the user
- * @returns an array of user objects that match the given user id
- */
- checkUserData(userId: string) {
- return this.firebaseService
- .getAllUsers()
- .filter((user) => user.id === userId);
+ loadUser(): void {
+ this.isLoading = true;
+
+ if (!this.selectedUserId) {
+ this.isLoading = false;
+ return;
+ }
+
+ this.userService
+ .getUserById(this.selectedUserId)
+ .pipe(finalize(() => (this.isLoading = false)))
+ .subscribe({
+ next: (response) => {
+ this.selectedUser = response;
+ },
+ error: (err) => {
+ console.error('Error loading the tasks:', err);
+ },
+ });
}
/**
diff --git a/src/app/components/contacts/contact-edit-new/contact-form/contact-form.component.ts b/src/app/components/contacts/contact-edit-new/contact-form/contact-form.component.ts
index 3ae68a1..ce0b9a1 100644
--- a/src/app/components/contacts/contact-edit-new/contact-form/contact-form.component.ts
+++ b/src/app/components/contacts/contact-edit-new/contact-form/contact-form.component.ts
@@ -54,7 +54,8 @@ export class ContactFormComponent implements OnInit, OnChanges {
phone: '',
initials: '',
color: '',
- status: false,
+ isContactOnly: true,
+ isOnline: false,
lastLogin: 0,
};
diff --git a/src/app/components/contacts/contacts.component.html b/src/app/components/contacts/contacts.component.html
index 533f861..138dd9d 100644
--- a/src/app/components/contacts/contacts.component.html
+++ b/src/app/components/contacts/contacts.component.html
@@ -2,7 +2,7 @@