Browse Source

feat: show the recent contacts in the alphabetical section of choosers

pull/219/head
Trent Larson 2 days ago
parent
commit
b1fa6ac458
  1. 15
      src/components/EntityGrid.vue

15
src/components/EntityGrid.vue

@ -307,14 +307,14 @@ export default class EntityGrid extends Vue {
} }
/** /**
* Get the 3 most recently added contacts (when showing contacts and not searching) * Get the most recently added contacts (when showing contacts and not searching)
*/ */
get recentContacts(): Contact[] { get recentContacts(): Contact[] {
if (this.entityType !== "people" || this.searchTerm.trim()) { if (this.entityType !== "people" || this.searchTerm.trim()) {
return []; return [];
} }
// Entities are already sorted by date added (newest first) // Entities are already sorted by date added (newest first)
return (this.entities as Contact[]).slice(0, 3); return (this.entities as Contact[]).slice(0, RECENT_CONTACTS_COUNT);
} }
/** /**
@ -325,16 +325,16 @@ export default class EntityGrid extends Vue {
if (this.entityType !== "people" || this.searchTerm.trim()) { if (this.entityType !== "people" || this.searchTerm.trim()) {
return []; return [];
} }
// Skip the first 3 (recent contacts) and sort the rest alphabetically // Skip the first few (recent contacts) and sort the rest alphabetically
// Create a copy to avoid mutating the original array // Create a copy to avoid mutating the original array
const remaining = (this.entities as Contact[]).slice(RECENT_CONTACTS_COUNT); const remaining = this.entities as Contact[];
const sorted = [...remaining].sort((a: Contact, b: Contact) => { const sorted = [...remaining].sort((a: Contact, b: Contact) => {
// Sort alphabetically by name, falling back to DID if name is missing // Sort alphabetically by name, falling back to DID if name is missing
const nameA = (a.name || a.did).toLowerCase(); const nameA = (a.name || a.did).toLowerCase();
const nameB = (b.name || b.did).toLowerCase(); const nameB = (b.name || b.did).toLowerCase();
return nameA.localeCompare(nameB); return nameA.localeCompare(nameB);
}); });
// Apply infinite scroll: show based on displayedCount (minus the 3 recent) // Apply infinite scroll: show based on displayedCount (minus the recent contacts)
const toShow = Math.max(0, this.displayedCount - RECENT_CONTACTS_COUNT); const toShow = Math.max(0, this.displayedCount - RECENT_CONTACTS_COUNT);
return sorted.slice(0, toShow); return sorted.slice(0, toShow);
} }
@ -531,9 +531,8 @@ export default class EntityGrid extends Vue {
} }
// People: check if more alphabetical contacts available // People: check if more alphabetical contacts available
// Total available = 3 recent + all alphabetical // Total available = recent + all alphabetical
const remaining = (this.entities as Contact[]).slice(RECENT_CONTACTS_COUNT); const totalAvailable = RECENT_CONTACTS_COUNT + this.entities.length;
const totalAvailable = RECENT_CONTACTS_COUNT + remaining.length;
return this.displayedCount < totalAvailable; return this.displayedCount < totalAvailable;
} }

Loading…
Cancel
Save