Skip to content

Commit

Permalink
just sort alphabetically
Browse files Browse the repository at this point in the history
Signed-off-by: ImUrX <urielfontan2002@gmail.com>

Fixes #1598 and #1599

Signed-off-by: ImUrX <urielfontan2002@gmail.com>

object is not a string

Signed-off-by: ImUrX <urielfontan2002@gmail.com>

use an and not an or

Signed-off-by: ImUrX <urielfontan2002@gmail.com>

check if findIndex gives -1

Signed-off-by: ImUrX <urielfontan2002@gmail.com>
  • Loading branch information
ImUrX committed May 25, 2020
1 parent df46053 commit f9bbdee
Showing 1 changed file with 39 additions and 23 deletions.
62 changes: 39 additions & 23 deletions src/views/Contacts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -223,29 +223,45 @@ export default {

// generate groups menu from groups store
groupsMenu() {
return this.groups.map(group => {
return {
id: group.name.replace(' ', '_'),
key: group.name.replace(' ', '_'),
router: {
name: 'group',
params: { selectedGroup: group.name },
},
text: group.name,
utils: {
counter: group.contacts.length,
actions: [
{
icon: 'icon-download',
text: 'Download',
action: () => this.downloadGroup(group),
},
],
},
}
}).sort(function(a, b) {
return parseInt(b.utils.counter) - parseInt(a.utils.counter)
})
const menu = this.groups.map(group => ({
id: group.name.replace(' ', '_'),
key: group.name.replace(' ', '_'),
router: {
name: 'group',
params: { selectedGroup: group.name },
},
text: group.name,
utils: {
counter: group.contacts.length,
actions: [
{
icon: 'icon-download',
text: 'Download',
action: () => this.downloadGroup(group),
},
],
},
toString: () => group.name,
}))
// Sort alphabetically
.sort()
// Sort decimally if it starts with a number
// could be better if it detects if any part has a number (but it would be more complex)
.sort((a, b) => {
const matchA = a.text.match(/^(\d+(?:\.\d+)?)/)
const matchB = b.text.match(/^(\d+(?:\.\d+)?)/)
if (!(matchA && matchB)) return 0
return parseFloat(matchA[0]) - parseFloat(matchB[0])
})
// Find the Recently Contacted group, delete it from array and put it at first place of the array
const recentlyIndex = menu.findIndex(
group => group.text === t('contactsinteraction', 'Recently contacted')
)
if (recentlyIndex >= 0) {
menu.unshift(menu.splice(recentlyIndex, 1)[0])
}

return menu
},

// building the main menu
Expand Down

0 comments on commit f9bbdee

Please sign in to comment.