Skip to content

Commit

Permalink
fix: added address type handling
Browse files Browse the repository at this point in the history
  • Loading branch information
isordo committed Jul 13, 2023
1 parent 3a3b1ee commit 59d7d4f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
<ion-content class="ion-padding">
<ng-container *ngIf="contacts$ | async as contacts">
<div class="contacts-wrapper" *ngFor="let key of getHeading(contacts)">
<h3 class="contacts-letter">{{key | uppercase}}</h3>
<h3 *ngIf="sortType === sortEnum.NAME; else default" class="contacts-letter">{{key | uppercase}}</h3>
<ng-template #default>
<h3 class="contacts-letter">{{key}}</h3>
</ng-template>
<div *ngFor="let contact of getContacts(contacts, key)">
<airgap-contact-book-contacts-item
[name]="contact.name"
Expand Down
19 changes: 13 additions & 6 deletions src/app/pages/contact-book-contacts/contact-book-contacts.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { ErrorCategory, handleErrorLocal } from 'src/app/services/error-handler/
import { NavigationService } from 'src/app/services/navigation/navigation.service'
import { ContactBookContactsPopoverComponent, SortType } from './contact-book-contacts-popover/contact-book-contacts-popover.component'

export type ContactBookFilterType = 'addedFrom' | 'date' | 'address' | 'name'

enum SortDirection {
ASCENDING = 'ASCENDING',
DESCENDING = 'DESCENDING'
Expand Down Expand Up @@ -98,25 +100,30 @@ export class ContactBookContactsPage implements OnInit {
this.suggestions = await this.contactsService.getSuggestions()
}

private getKey(): string {
private getKey(): ContactBookFilterType {
switch (this.sortType) {
case SortType.ADDED_BY:
return 'addedFrom'
case SortType.DATE_CREATION:
return 'date'
case SortType.ADDRESS:
return 'address'
default:
return 'name'
}
}

getHeading(contacts: ContactInfo[]) {
public getHeading(contacts: ContactInfo[]) {
const key = this.getKey()
return Array.from(new Set(contacts.map(contact => String(contact[key]).charAt(0)))).sort()
return key === 'name'
? Array.from(new Set(contacts.map((contact) => String(contact[key]).charAt(0)))).sort()
: Array.from(new Set(contacts.map((contact) => String(contact[key])))).sort()
}

getContacts(contacts: ContactInfo[], key: string) {
public getContacts(contacts: ContactInfo[], key: string) {
const _key = this.getKey()
return contacts.filter(contact => String(contact[_key]).charAt(0) === key)
return _key === 'name'
? contacts.filter((contact) => String(contact[_key]).charAt(0) === key)
: contacts.filter((contact) => String(contact[_key]) === key)
}

}

0 comments on commit 59d7d4f

Please sign in to comment.