diff --git a/src/components/list/partials/filter-popup.vue b/src/components/list/partials/filter-popup.vue index 20d57ca58..30cc98cab 100644 --- a/src/components/list/partials/filter-popup.vue +++ b/src/components/list/partials/filter-popup.vue @@ -34,7 +34,7 @@ import {computed, ref, watch} from 'vue' import Filters from '@/components/list/partials/filters.vue' -import {getDefaultParams} from '@/composables/taskList' +import {getDefaultParams} from '@/composables/useTaskList' const props = defineProps({ modelValue: { diff --git a/src/components/list/partials/filters.vue b/src/components/list/partials/filters.vue index d9a0a46e2..073af33f3 100644 --- a/src/components/list/partials/filters.vue +++ b/src/components/list/partials/filters.vue @@ -212,7 +212,7 @@ import EditLabels from '@/components/tasks/partials/editLabels.vue' import {dateIsValid, formatISO} from '@/helpers/time/formatDate' import {objectToSnakeCase} from '@/helpers/case' -import {getDefaultParams} from '@/composables/taskList' +import {getDefaultParams} from '@/composables/useTaskList' import {camelCase} from 'camel-case' // FIXME: merge with DEFAULT_PARAMS in taskList.js diff --git a/src/composables/taskList.ts b/src/composables/useTaskList.ts similarity index 93% rename from src/composables/taskList.ts rename to src/composables/useTaskList.ts index 85fdc23b7..5f0dc06a1 100644 --- a/src/composables/taskList.ts +++ b/src/composables/useTaskList.ts @@ -18,23 +18,12 @@ const SORT_BY_DEFAULT = { id: 'desc', } -/** - * This mixin provides a base set of methods and properties to get tasks on a list. - */ -export function useTaskList(listId, sortByDefault = SORT_BY_DEFAULT) { - const params = ref({...getDefaultParams()}) - - const search = ref('') - const page = ref(1) - - const sortBy = ref({ ...sortByDefault }) - // This makes sure an id sort order is always sorted last. // When tasks would be sorted first by id and then by whatever else was specified, the id sort takes // precedence over everything else, making any other sort columns pretty useless. - function formatSortOrder(params) { + function formatSortOrder(sortBy, params) { let hasIdFilter = false - const sortKeys = Object.keys(sortBy.value) + const sortKeys = Object.keys(sortBy) for (const s of sortKeys) { if (s === 'id') { sortKeys.splice(s, 1) @@ -46,11 +35,24 @@ export function useTaskList(listId, sortByDefault = SORT_BY_DEFAULT) { sortKeys.push('id') } params.sort_by = sortKeys - params.order_by = sortKeys.map(s => sortBy.value[s]) + params.order_by = sortKeys.map(s => sortBy[s]) return params } +/** + * This mixin provides a base set of methods and properties to get tasks on a list. + */ +export function useTaskList(listId, sortByDefault = SORT_BY_DEFAULT) { + const params = ref({...getDefaultParams()}) + + const search = ref('') + const page = ref(1) + + const sortBy = ref({ ...sortByDefault }) + + + const getAllTasksParams = computed(() => { let loadParams = {...params.value} @@ -58,7 +60,7 @@ export function useTaskList(listId, sortByDefault = SORT_BY_DEFAULT) { loadParams.s = search.value } - loadParams = formatSortOrder(loadParams) + loadParams = formatSortOrder(sortBy.value, loadParams) return [ {listId: listId.value}, diff --git a/src/views/list/ListList.vue b/src/views/list/ListList.vue index 057563f6b..7eb5a260d 100644 --- a/src/views/list/ListList.vue +++ b/src/views/list/ListList.vue @@ -154,7 +154,7 @@ import Nothing from '@/components/misc/nothing.vue' import Pagination from '@/components/misc/pagination.vue' import {ALPHABETICAL_SORT} from '@/components/list/partials/filters.vue' -import {useTaskList} from '@/composables/taskList' +import {useTaskList} from '@/composables/useTaskList' import {RIGHTS as Rights} from '@/constants/rights' import {calculateItemPosition} from '@/helpers/calculateItemPosition' import type {ITask} from '@/modelTypes/ITask' diff --git a/src/views/list/ListTable.vue b/src/views/list/ListTable.vue index ff388dc2e..50f0e3804 100644 --- a/src/views/list/ListTable.vue +++ b/src/views/list/ListTable.vue @@ -196,7 +196,7 @@ import FilterPopup from '@/components/list/partials/filter-popup.vue' import Pagination from '@/components/misc/pagination.vue' import Popup from '@/components/misc/popup.vue' -import {useTaskList} from '@/composables/taskList' +import {useTaskList} from '@/composables/useTaskList' import type {ITask} from '@/modelTypes/ITask' const ACTIVE_COLUMNS_DEFAULT = {