Skip to content

Commit

Permalink
feat: Add favorite section to contact list
Browse files Browse the repository at this point in the history
  • Loading branch information
Merkur39 committed Nov 18, 2024
1 parent 243722e commit 6434a1a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/helpers/contactList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 8 additions & 14 deletions src/helpers/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
])
}

/**
Expand All @@ -164,10 +158,10 @@ export const reworkContacts = (
contactsWithNoIndexes
) => {
const reworkedContacts = hasServiceBeenLaunched
? moveMyselfToFirstPosition(
? moveMyselfAndFavoritesToFirstPosition(
contactsWithIndexes.concat(contactsWithNoIndexes)
)
: moveMyselfToFirstPosition(
: moveMyselfAndFavoritesToFirstPosition(
harmonizeAndSortByFamilyNameGivenNameEmailCozyUrl(
contactsWithIndexes,
contactsWithNoIndexes
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"contact_info": "Contact informations",
"contact_group": "Groups",
"me": "me",
"favorite": "Favorites",
"empty-list": "EMPTY",
"search": "Search",
"empty": {
Expand Down
1 change: 1 addition & 0 deletions src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"contact_info": "Coordonnées",
"contact_group": "Groupes",
"me": "moi",
"favorite": "Favoris",
"empty-list": "VIDE",
"search": "Rechercher",
"empty": {
Expand Down

0 comments on commit 6434a1a

Please sign in to comment.