From 661dd793d79d642743a6604a75c8510c5033355e Mon Sep 17 00:00:00 2001 From: AlexisG Date: Mon, 18 Nov 2024 10:18:57 +0100 Subject: [PATCH] feat: Add favorite section to contact list --- src/helpers/contactList.js | 1 + src/helpers/contacts.js | 22 ++++++++-------------- src/locales/en.json | 1 + src/locales/fr.json | 1 + 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/helpers/contactList.js b/src/helpers/contactList.js index f26297564..7c5e55b9b 100644 --- a/src/helpers/contactList.js +++ b/src/helpers/contactList.js @@ -3,6 +3,7 @@ import removeAccents from 'remove-accents' const makeHeader = (contact, t) => { if (contact.me) return t('me') + if (contact.cozyMetadata?.favorite) return t('favorite') const index = get(contact, 'indexes.byFamilyNameGivenNameEmailCozyUrl', '') const hasIndex = index !== null && index.length > 0 diff --git a/src/helpers/contacts.js b/src/helpers/contacts.js index 57ed19525..a183c45d9 100644 --- a/src/helpers/contacts.js +++ b/src/helpers/contacts.js @@ -2,8 +2,6 @@ import sortBy from 'lodash/sortBy' import { models, HasMany } from 'cozy-client' -import { filterWithRemaining } from './filterWithRemaining' - const { makeFullname, makeDefaultSortIndexValue, makeDisplayName } = models.contact @@ -136,19 +134,15 @@ export const harmonizeAndSortByFamilyNameGivenNameEmailCozyUrl = ( } /** - * Move myself to first position in contacts list + * Sort contacts list by myself and favorites * @param {object[]} contacts - contacts list * @returns {object[]} */ -const moveMyselfToFirstPosition = contacts => { - const { - itemsFound: [mySelf], - remainingItems: contactsWithoutMySelf - } = filterWithRemaining(contacts, contact => contact.me) - - if (mySelf) return [mySelf, ...contactsWithoutMySelf] - - return contacts +const moveMyselfAndFavoritesToFirstPosition = contacts => { + return sortBy(contacts, [ + contact => !contact.me, + contact => !contact.cozyMetadata?.favorite + ]) } /** @@ -164,10 +158,10 @@ export const reworkContacts = ( contactsWithNoIndexes ) => { const reworkedContacts = hasServiceBeenLaunched - ? moveMyselfToFirstPosition( + ? moveMyselfAndFavoritesToFirstPosition( contactsWithIndexes.concat(contactsWithNoIndexes) ) - : moveMyselfToFirstPosition( + : moveMyselfAndFavoritesToFirstPosition( harmonizeAndSortByFamilyNameGivenNameEmailCozyUrl( contactsWithIndexes, contactsWithNoIndexes diff --git a/src/locales/en.json b/src/locales/en.json index db6be6d87..5ca730d3d 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -17,6 +17,7 @@ "contact_info": "Contact informations", "contact_group": "Groups", "me": "me", + "favorite": "Favorites", "empty-list": "EMPTY", "search": "Search", "empty": { diff --git a/src/locales/fr.json b/src/locales/fr.json index e9aa10e46..cfab947f3 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -17,6 +17,7 @@ "contact_info": "Coordonnées", "contact_group": "Groupes", "me": "moi", + "favorite": "Favoris", "empty-list": "VIDE", "search": "Rechercher", "empty": {