Fix sorting by priority
This commit is contained in:
parent
1f639506d7
commit
281f8fc9b8
1 changed files with 20 additions and 1 deletions
|
@ -127,7 +127,7 @@ function sort(tasks, sortOrder, sortDirection) {
|
|||
break
|
||||
}
|
||||
case 'priority': {
|
||||
sortedTasks = tasks.sort((taskA, taskB) => taskA.priority - taskB.priority)
|
||||
sortedTasks = sortByPriority(tasks)
|
||||
break
|
||||
}
|
||||
case 'due': {
|
||||
|
@ -144,6 +144,25 @@ function sort(tasks, sortOrder, sortDirection) {
|
|||
return sortDirection ? sortedTasks.reverse() : sortedTasks
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts tasks by priority in ascending order
|
||||
*
|
||||
* Sorting by priority is a bit tricky, because
|
||||
* 0 means no priority, but 1 is highest priority and 9 is lowest priority.
|
||||
* Hence, sort order must be 1, 2, ..., 9, 0
|
||||
*
|
||||
* @param {Array} tasks The tasks to be sorted
|
||||
* @returns {Array}
|
||||
*/
|
||||
function sortByPriority(tasks) {
|
||||
return tasks.sort((taskA, taskB) => {
|
||||
if (-taskA.priority === -taskB.priority) return 0
|
||||
if (-taskA.priority === 0) return 1
|
||||
if (-taskB.priority === 0) return -1
|
||||
return taskA.priority - taskB.priority
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts tasks alphabetically in ascending order
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue