1
0

fix(tasks): reset page number when applying filters

Resolves https://community.vikunja.io/t/when-filter-conditions-change-pages-arent-updated-according-to-new-list-length/1601
This commit is contained in:
kolaente
2023-09-06 10:50:52 +02:00
parent 4e5823183e
commit 1918947c0b
3 changed files with 44 additions and 7 deletions

View File

@ -1,5 +1,6 @@
import {ref, shallowReactive, watch, computed, type ComputedGetter} from 'vue'
import {useRoute} from 'vue-router'
import {useRouteQuery} from '@vueuse/router'
import TaskCollectionService from '@/services/taskCollection'
import type {ITask} from '@/modelTypes/ITask'
@ -68,23 +69,33 @@ export function useTaskList(projectIdGetter: ComputedGetter<IProject['id']>, sor
const params = ref({...getDefaultParams()})
const search = ref('')
const page = ref(1)
const page = useRouteQuery('page', '1', { transform: Number })
const sortBy = ref({ ...sortByDefault })
const getAllTasksParams = computed(() => {
let loadParams = {...params.value}
const allParams = computed(() => {
const loadParams = {...params.value}
if (search.value !== '') {
loadParams.s = search.value
}
loadParams = formatSortOrder(sortBy.value, loadParams)
return formatSortOrder(sortBy.value, loadParams)
})
watch(
() => allParams.value,
() => {
// When parameters change, the page should always be the first
page.value = 1
},
)
const getAllTasksParams = computed(() => {
return [
{projectId: projectId.value},
loadParams,
page.value || 1,
allParams.value,
page.value,
]
})