From aa2278a56411dc8045fa468b090755cf5d899d09 Mon Sep 17 00:00:00 2001 From: Dominik Pschenitschni Date: Thu, 27 Oct 2022 15:47:03 +0200 Subject: [PATCH 1/2] chore: move helper function outside of composable --- src/composables/taskList.ts | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/composables/taskList.ts b/src/composables/taskList.ts index e23f10087..23a33f0c0 100644 --- a/src/composables/taskList.ts +++ b/src/composables/taskList.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}, From 7ce880239ec3ce16313d93bfefa657c499bbfb29 Mon Sep 17 00:00:00 2001 From: Dominik Pschenitschni Date: Thu, 27 Oct 2022 15:47:48 +0200 Subject: [PATCH 2/2] feat: rename useTaskList --- src/components/list/partials/filter-popup.vue | 2 +- src/components/list/partials/filters.vue | 2 +- src/composables/{taskList.ts => useTaskList.ts} | 0 src/views/list/ListList.vue | 2 +- src/views/list/ListTable.vue | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) rename src/composables/{taskList.ts => useTaskList.ts} (100%) 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 100% rename from src/composables/taskList.ts rename to src/composables/useTaskList.ts 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 = {