1
0

fix: rely on api to properly sort tasks on home page (#1997)

This PR changes the behaviour of how tasks are sorted. Before, the frontend would sort tasks but this resulted in some cases where tasks were not sorted properly. Most of this is test code to reliably reproduce the problem and make fixing it easier.
The actual bug was in Vikunja's api, therefore I've removed all sorting of tasks in the frontend and ensured the api properly sorts tasks.

Fixes https://github.com/go-vikunja/frontend/issues/54

Depends on https://kolaente.dev/vikunja/api/pulls/1177

Co-authored-by: kolaente <k@knt.li>
Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/1997
Reviewed-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de>
This commit is contained in:
konrad
2022-06-01 16:59:59 +00:00
parent 402b0b2acf
commit efed128f03
5 changed files with 171 additions and 28 deletions

View File

@ -1,5 +1,5 @@
<template>
<div class="is-max-width-desktop has-text-left ">
<div class="is-max-width-desktop has-text-left" v-cy="'showTasks'">
<h3 class="mb-2 title">
{{ pageTitle }}
</h3>
@ -32,9 +32,8 @@
>
<div class="p-2">
<single-task-in-list
v-for="t in tasksSorted"
v-for="t in tasks"
:key="t.id"
class="task"
:show-list="true"
:the-task="t"
@taskUpdated="updateTasks"/>
@ -104,28 +103,6 @@ const pageTitle = computed(() => {
until: formatDate(dateTo, 'PPP'),
})
})
const tasksSorted = computed(() => {
// 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.
const tasksWithDueDate = [...tasks.value]
.filter(t => t.dueDate !== null)
.sort((a, b) => {
const sortByDueDate = a.dueDate - b.dueDate
return sortByDueDate === 0
? b.id - a.id
: sortByDueDate
})
const tasksWithoutDueDate = [...tasks.value]
.filter(t => t.dueDate === null)
return [
...tasksWithDueDate,
...tasksWithoutDueDate,
]
})
const hasTasks = computed(() => tasks.value && tasks.value.length > 0)
const userAuthenticated = computed(() => store.state.auth.authenticated)
const loading = computed(() => store.state[LOADING] && store.state[LOADING_MODULE] === 'tasks')
@ -178,7 +155,7 @@ async function loadPendingTasks(from: string, to: string) {
const params = {
sortBy: ['due_date', 'id'],
orderBy: ['desc', 'desc'],
orderBy: ['asc', 'desc'],
filterBy: ['done'],
filterValue: ['false'],
filterComparator: ['equals'],