docs: add comments to ContactDetailComponent for better code understanding
This commit is contained in:
parent
3898a9a2f1
commit
0c29600736
6 changed files with 89 additions and 55 deletions
|
|
@ -10,11 +10,13 @@
|
||||||
<div
|
<div
|
||||||
class="btn-back"
|
class="btn-back"
|
||||||
[ngClass]="{ 'd-none': !selectedUserId }"
|
[ngClass]="{ 'd-none': !selectedUserId }"
|
||||||
(click)="closeUserDetails()"
|
(click)="emitCloseContact()"
|
||||||
>
|
>
|
||||||
<img src="./../../../../assets/img/arrow-left.svg" />
|
<img src="./../../../../assets/img/arrow-left.svg" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Show contact details if a user is selected -->
|
||||||
@if (selectedUser && selectedUserId) {
|
@if (selectedUser && selectedUserId) {
|
||||||
<div
|
<div
|
||||||
class="contact-details"
|
class="contact-details"
|
||||||
|
|
@ -29,6 +31,7 @@
|
||||||
'background-color': selectedUser.color
|
'background-color': selectedUser.color
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
|
<!-- Show online icon if user is online, else offline icon -->
|
||||||
@if(selectedUser.isOnline) {
|
@if(selectedUser.isOnline) {
|
||||||
<img src="./../../../assets/img/online.svg" alt="" />
|
<img src="./../../../assets/img/online.svg" alt="" />
|
||||||
} @else {
|
} @else {
|
||||||
|
|
@ -42,10 +45,14 @@
|
||||||
<div class="name">
|
<div class="name">
|
||||||
{{ selectedUser.firstName }}
|
{{ selectedUser.firstName }}
|
||||||
{{ selectedUser.lastName }}
|
{{ selectedUser.lastName }}
|
||||||
|
|
||||||
|
<!-- Show "you" if contact is logged in user -->
|
||||||
@if (currentUser && selectedUser.id === currentUser.id) {
|
@if (currentUser && selectedUser.id === currentUser.id) {
|
||||||
{{ "contacts.you" | translate }}
|
{{ "contacts.you" | translate }}
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Show edit and delete buttons if user is not contact only -->
|
||||||
@if(selectedUser.isContactOnly || currentUser && selectedUser.id ===
|
@if(selectedUser.isContactOnly || currentUser && selectedUser.id ===
|
||||||
currentUser.id) {
|
currentUser.id) {
|
||||||
<div class="btns">
|
<div class="btns">
|
||||||
|
|
@ -55,6 +62,8 @@
|
||||||
{{ "contacts.btnEdit0" | translate }}
|
{{ "contacts.btnEdit0" | translate }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Show delete button if user is not contact only -->
|
||||||
@if (selectedUser.isContactOnly || currentUser && selectedUser.id !==
|
@if (selectedUser.isContactOnly || currentUser && selectedUser.id !==
|
||||||
currentUser.id) {
|
currentUser.id) {
|
||||||
<div class="btn btn-delete" (click)="toggleConfirmDialog()">
|
<div class="btn btn-delete" (click)="toggleConfirmDialog()">
|
||||||
|
|
@ -78,16 +87,23 @@
|
||||||
<a [href]="'mail:' + selectedUser.email">
|
<a [href]="'mail:' + selectedUser.email">
|
||||||
{{ selectedUser.email }}
|
{{ selectedUser.email }}
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
<!-- Show phone number if it exists -->
|
||||||
|
@if(selectedUser.phone) {
|
||||||
<p>{{ "contacts.contactPhone" | translate }}</p>
|
<p>{{ "contacts.contactPhone" | translate }}</p>
|
||||||
@if(selectedUser.phone === '') {
|
|
||||||
<span>{{ "contacts.contactPhoneTxT" | translate }}</span> } @else {
|
|
||||||
<a [href]="'tel:' + selectedUser.phone">
|
<a [href]="'tel:' + selectedUser.phone">
|
||||||
<span>{{ selectedUser.phone }}</span>
|
<span>{{ selectedUser.phone }}</span>
|
||||||
</a>
|
</a>
|
||||||
} @if(selectedUser.id !== "") {
|
}
|
||||||
|
<!-- Show last login if user is not contact only -->
|
||||||
|
@if(!selectedUser.isContactOnly) {
|
||||||
<p>{{ "contacts.contactLastOnline" | translate }}</p>
|
<p>{{ "contacts.contactLastOnline" | translate }}</p>
|
||||||
|
|
||||||
|
<!-- Show last login if user is online, else if user has never logged in, else show last login -->
|
||||||
@if(selectedUser.isOnline) {
|
@if(selectedUser.isOnline) {
|
||||||
<span>{{ "contacts.contactLastOnlineTxt" | translate }}</span>
|
<span>{{ "contacts.contactCurrentlyOnline" | translate }}</span>
|
||||||
|
} @else if (!selectedUser.lastLogin ) {
|
||||||
|
<span>{{ "contacts.contactNeverSeenOnline" | translate }}</span>
|
||||||
} @else {
|
} @else {
|
||||||
<span
|
<span
|
||||||
>{{ selectedUser.lastLogin | date : "dd. MMM yyyy, HH:mm:ss" }}
|
>{{ selectedUser.lastLogin | date : "dd. MMM yyyy, HH:mm:ss" }}
|
||||||
|
|
@ -96,10 +112,12 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
} @if (isMobileNavbarOpen) {
|
} @if (showMobileNavbar) {
|
||||||
<!-- TODO -->
|
<!-- TODO -->
|
||||||
}
|
}
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<!-- Confirm dialog -->
|
||||||
<app-confirm-dialog
|
<app-confirm-dialog
|
||||||
*ngIf="showConfirmDialog"
|
*ngIf="showConfirmDialog"
|
||||||
[message]="'confirmDialogComponent.deleteContact' | translate"
|
[message]="'confirmDialogComponent.deleteContact' | translate"
|
||||||
|
|
|
||||||
|
|
@ -26,11 +26,11 @@ import { ConfirmDialogComponent } from '../../../shared/components/confirm-dialo
|
||||||
export class ContactDetailComponent {
|
export class ContactDetailComponent {
|
||||||
@Input() selectedUserId: string | null = null;
|
@Input() selectedUserId: string | null = null;
|
||||||
@Input() currentUser: User | null = null;
|
@Input() currentUser: User | null = null;
|
||||||
@Output() closeContactEmitter = new EventEmitter<boolean>();
|
@Output() contactClosed = new EventEmitter<boolean>();
|
||||||
|
|
||||||
isLoading: boolean = false;
|
|
||||||
selectedUser: User | null = null;
|
selectedUser: User | null = null;
|
||||||
isMobileNavbarOpen: boolean = false;
|
isLoading = false;
|
||||||
|
showMobileNavbar = false;
|
||||||
showConfirmDialog = false;
|
showConfirmDialog = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
|
@ -41,11 +41,15 @@ export class ContactDetailComponent {
|
||||||
private updateNotifierService: UpdateNotifierService
|
private updateNotifierService: UpdateNotifierService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnChanges(changes: SimpleChanges) {
|
/**
|
||||||
if (
|
* If the `selectedUserId` input property changes and has a current value,
|
||||||
changes['selectedUserId'] !== undefined &&
|
* it loads the user data. Otherwise, it resets the `selectedUser` to null.
|
||||||
changes['selectedUserId'].currentValue !== ''
|
*
|
||||||
) {
|
* @param changes An object of key-value pairs representing the changed properties.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ngOnChanges(changes: SimpleChanges): void {
|
||||||
|
if (changes['selectedUserId']?.currentValue) {
|
||||||
this.loadUser();
|
this.loadUser();
|
||||||
} else {
|
} else {
|
||||||
this.selectedUser = null;
|
this.selectedUser = null;
|
||||||
|
|
@ -53,13 +57,56 @@ export class ContactDetailComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the contact details view by resetting the current user id in the
|
* Emits an event with the value false to trigger the contact list to close.
|
||||||
* shared service and emitting the closeContactEmitter event.
|
|
||||||
*/
|
*/
|
||||||
closeUserDetails() {
|
emitCloseContact() {
|
||||||
this.closeContactEmitter.emit();
|
this.contactClosed.emit(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggles the visibility of the mobile contact details navbar.
|
||||||
|
*/
|
||||||
|
toggleNav(): void {
|
||||||
|
this.showMobileNavbar = !this.showMobileNavbar;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggles the visibility of the confirmation dialog.
|
||||||
|
* This method switches the `showConfirmDialog` boolean state.
|
||||||
|
*/
|
||||||
|
toggleConfirmDialog(): void {
|
||||||
|
this.showConfirmDialog = !this.showConfirmDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the overlay data for the contact overlay to the given user data,
|
||||||
|
* and hides the mobile contact details navbar.
|
||||||
|
*
|
||||||
|
* @param userData The user data to be edited.
|
||||||
|
*/
|
||||||
|
editContact(userData: User) {
|
||||||
|
this.overlayService.setOverlayData('contactOverlay', userData);
|
||||||
|
this.showMobileNavbar = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the contact with the given id, shows a success toast, triggers an update of the contact list,
|
||||||
|
* and closes the contact details component.
|
||||||
|
*/
|
||||||
|
async deleteContact() {
|
||||||
|
try {
|
||||||
|
await lastValueFrom(this.apiService.deleteUserById(this.selectedUserId!));
|
||||||
|
this.toastNotificationService.deleteContactSuccessToast();
|
||||||
|
this.updateNotifierService.notifyUpdate('contact');
|
||||||
|
this.emitCloseContact();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the user data with the given id and sets it to the `selectedUser` property.
|
||||||
|
*/
|
||||||
loadUser(): void {
|
loadUser(): void {
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
|
|
||||||
|
|
@ -80,37 +127,4 @@ export class ContactDetailComponent {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Toggles the mobile navigation bar on and off.
|
|
||||||
* @remarks This method is used by the contact details component to toggle
|
|
||||||
* the mobile navigation bar when the user clicks the three points icon.
|
|
||||||
*/
|
|
||||||
toggleNav() {
|
|
||||||
this.isMobileNavbarOpen = !this.isMobileNavbarOpen;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Opens the edit contact dialog by setting the appropriate flags in the shared service.
|
|
||||||
* This method is used by the contact details component to open the edit contact dialog when the user clicks the edit button.
|
|
||||||
*/
|
|
||||||
editContact(userData: User) {
|
|
||||||
this.overlayService.setOverlayData('contactOverlay', userData);
|
|
||||||
this.isMobileNavbarOpen = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
toggleConfirmDialog() {
|
|
||||||
this.showConfirmDialog = !this.showConfirmDialog;
|
|
||||||
}
|
|
||||||
|
|
||||||
async deleteContact() {
|
|
||||||
try {
|
|
||||||
await lastValueFrom(this.apiService.deleteUserById(this.selectedUserId!));
|
|
||||||
this.toastNotificationService.deleteContactSuccessToast();
|
|
||||||
this.updateNotifierService.notifyUpdate('contact');
|
|
||||||
this.closeUserDetails();
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@
|
||||||
}"
|
}"
|
||||||
[selectedUserId]="selectedUserId"
|
[selectedUserId]="selectedUserId"
|
||||||
[currentUser]="currentUser"
|
[currentUser]="currentUser"
|
||||||
(closeContactEmitter)="closeContactEmitter()"
|
(contactClosed)="handleCloseContact()"
|
||||||
></app-contact-detail>
|
></app-contact-detail>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ export class ContactsComponent {
|
||||||
/**
|
/**
|
||||||
* Triggers the resize function to adjust UI elements based on the current state.
|
* Triggers the resize function to adjust UI elements based on the current state.
|
||||||
*/
|
*/
|
||||||
closeContactEmitter() {
|
handleCloseContact() {
|
||||||
this.selectedUserId = null;
|
this.selectedUserId = null;
|
||||||
this.onResize();
|
this.onResize();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,8 @@
|
||||||
"contactPhone": "Telefon",
|
"contactPhone": "Telefon",
|
||||||
"contactPhoneTxT": "Keine Telefonnummer",
|
"contactPhoneTxT": "Keine Telefonnummer",
|
||||||
"contactLastOnline": "Zuletzt online gesehen",
|
"contactLastOnline": "Zuletzt online gesehen",
|
||||||
"contactLastOnlineTxt": "Derzeit online",
|
"contactCurrentlyOnline": "Derzeit online",
|
||||||
|
"contactNeverSeenOnline": "Niemals online gesehen",
|
||||||
"addContact": "Kontakt hinzufügen",
|
"addContact": "Kontakt hinzufügen",
|
||||||
"editContact": "Kontakt bearbeiten",
|
"editContact": "Kontakt bearbeiten",
|
||||||
"firstName": "Vorname",
|
"firstName": "Vorname",
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,8 @@
|
||||||
"contactPhone": "Phone",
|
"contactPhone": "Phone",
|
||||||
"contactPhoneTxT": "No phone number",
|
"contactPhoneTxT": "No phone number",
|
||||||
"contactLastOnline": "Last seen online",
|
"contactLastOnline": "Last seen online",
|
||||||
"contactLastOnlineTxt": "Currently online",
|
"contactCurrentlyOnline": "Currently online",
|
||||||
|
"contactNeverSeenOnline": "Never seen online",
|
||||||
"editContact": "Edit contact",
|
"editContact": "Edit contact",
|
||||||
"addContact": "Add contact",
|
"addContact": "Add contact",
|
||||||
"firstName": "First name",
|
"firstName": "First name",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue