From df32893ce657bc57a6a5f9b850e23d7e814d76db Mon Sep 17 00:00:00 2001 From: kolaente Date: Sat, 16 Oct 2021 21:37:21 +0200 Subject: [PATCH] fix: always sort tasks the same order in chrome and firefox Discussion at https://community.vikunja.io/t/custom-sorting-tasks-on-overview/392 --- src/views/tasks/ShowTasks.vue | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/views/tasks/ShowTasks.vue b/src/views/tasks/ShowTasks.vue index 601e110c..015044d3 100644 --- a/src/views/tasks/ShowTasks.vue +++ b/src/views/tasks/ShowTasks.vue @@ -33,12 +33,15 @@
{{ $t('task.show.today') }} - {{ $t('task.show.nextWeek') }} + {{ + $t('task.show.nextWeek') + }} + {{ $t('task.show.nextMonth') }}
@@ -163,7 +166,10 @@ export default { if (this.showAll) { this.setTitle(this.$t('task.show.titleCurrent')) } else { - this.setTitle(this.$t('task.show.titleDates', { from: this.cStartDate.toLocaleDateString(), to: this.cEndDate.toLocaleDateString()})) + this.setTitle(this.$t('task.show.titleDates', { + from: this.cStartDate.toLocaleDateString(), + to: this.cEndDate.toLocaleDateString(), + })) } const params = { @@ -200,14 +206,17 @@ export default { this.$store.dispatch('tasks/loadTasks', params) .then(r => { - // Sort all tasks to put those with a due date before the ones without a due date, the - // soonest before the later ones. - // We can't use the api sorting here because that sorts tasks with a due date after - // ones without a due date. - r.sort((a, b) => { - return a.dueDate === null && b.dueDate === null ? -1 : 1 - }) - const tasks = r.filter(t => t.dueDate !== null).concat(r.filter(t => t.dueDate === null)) + // Sorting tasks with a due date so that the soonest or overdue are displayed at the top of the list. + const tasksWithDueDates = r + .filter(t => t.dueDate !== null) + .sort((a, b) => a.dueDate > b.dueDate ? 1 : -1) + + const tasksWithoutDueDates = r.filter(t => t.dueDate === null) + + const tasks = [ + ...tasksWithDueDates, + ...tasksWithoutDueDates, + ] this.$set(this, 'tasks', tasks) })