1
0

feat: remove props destructuring from ShowTasks

This commit is contained in:
Dominik Pschenitschni 2024-07-05 15:06:22 +02:00 committed by konrad
parent fd3f1de861
commit d02c349231

View File

@ -87,19 +87,16 @@ import {useTaskStore} from '@/stores/tasks'
import {useProjectStore} from '@/stores/projects' import {useProjectStore} from '@/stores/projects'
import type {TaskFilterParams} from '@/services/taskCollection' import type {TaskFilterParams} from '@/services/taskCollection'
// Linting disabled because we explicitely enabled destructuring in vite's config, this will work. const props = withDefaults(defineProps<{
// eslint-disable-next-line vue/no-setup-props-destructure
const {
dateFrom,
dateTo,
showNulls = false,
showOverdue = false,
} = defineProps<{
dateFrom?: Date | string, dateFrom?: Date | string,
dateTo?: Date | string, dateTo?: Date | string,
showNulls?: boolean, showNulls?: boolean,
showOverdue?: boolean, showOverdue?: boolean,
}>() }>(), {
showNulls: false,
showOverdue: false,
})
const authStore = useAuthStore() const authStore = useAuthStore()
const taskStore = useTaskStore() const taskStore = useTaskStore()
const route = useRoute() const route = useRoute()
@ -113,13 +110,13 @@ const projectStore = useProjectStore()
setTimeout(() => showNothingToDo.value = true, 100) setTimeout(() => showNothingToDo.value = true, 100)
const showAll = computed(() => typeof dateFrom === 'undefined' || typeof dateTo === 'undefined') const showAll = computed(() => typeof props.dateFrom === 'undefined' || typeof props.dateTo === 'undefined')
const pageTitle = computed(() => { const pageTitle = computed(() => {
// We need to define "key" because it is the first parameter in the array and we need the second // We need to define "key" because it is the first parameter in the array and we need the second
const predefinedRange = Object.entries(DATE_RANGES) const predefinedRange = Object.entries(DATE_RANGES)
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
.find(([, value]) => dateFrom === value[0] && dateTo === value[1]) .find(([, value]) => props.dateFrom === value[0] && props.dateTo === value[1])
?.[0] ?.[0]
if (typeof predefinedRange !== 'undefined') { if (typeof predefinedRange !== 'undefined') {
return t(`input.datepickerRange.ranges.${predefinedRange}`) return t(`input.datepickerRange.ranges.${predefinedRange}`)
@ -128,8 +125,8 @@ const pageTitle = computed(() => {
return showAll.value return showAll.value
? t('task.show.titleCurrent') ? t('task.show.titleCurrent')
: t('task.show.fromuntil', { : t('task.show.fromuntil', {
from: formatDate(dateFrom, 'PPP'), from: formatDate(props.dateFrom, 'PPP'),
until: formatDate(dateTo, 'PPP'), until: formatDate(props.dateTo, 'PPP'),
}) })
}) })
const hasTasks = computed(() => tasks.value && tasks.value.length > 0) const hasTasks = computed(() => tasks.value && tasks.value.length > 0)
@ -145,10 +142,10 @@ function setDate(dates: dateStrings) {
router.push({ router.push({
name: route.name as string, name: route.name as string,
query: { query: {
from: dates.dateFrom ?? dateFrom, from: dates.dateFrom ?? props.dateFrom,
to: dates.dateTo ?? dateTo, to: dates.dateTo ?? props.dateTo,
showOverdue: showOverdue ? 'true' : 'false', showOverdue: props.showOverdue ? 'true' : 'false',
showNulls: showNulls ? 'true' : 'false', showNulls: props.showNulls ? 'true' : 'false',
}, },
}) })
} }
@ -186,7 +183,7 @@ async function loadPendingTasks(from: Date|string, to: Date|string) {
sort_by: ['due_date', 'id'], sort_by: ['due_date', 'id'],
order_by: ['asc', 'desc'], order_by: ['asc', 'desc'],
filter: 'done = false', filter: 'done = false',
filter_include_nulls: showNulls, filter_include_nulls: props.showNulls,
s: '', s: '',
} }
@ -197,7 +194,7 @@ async function loadPendingTasks(from: Date|string, to: Date|string) {
// NOTE: Ideally we could also show tasks with a start or end date in the specified range, but the api // NOTE: Ideally we could also show tasks with a start or end date in the specified range, but the api
// is not capable (yet) of combining multiple filters with 'and' and 'or'. // is not capable (yet) of combining multiple filters with 'and' and 'or'.
if (!showOverdue) { if (!props.showOverdue) {
params.filter += ` && due_date > '${from instanceof Date ? from.toISOString() : from}'` params.filter += ` && due_date > '${from instanceof Date ? from.toISOString() : from}'`
} }
} }
@ -225,7 +222,7 @@ function updateTasks(updatedTask: ITask) {
} }
} }
watchEffect(() => loadPendingTasks(dateFrom as string, dateTo as string)) watchEffect(() => loadPendingTasks(props.dateFrom, props.dateTo))
watchEffect(() => setTitle(pageTitle.value)) watchEffect(() => setTitle(pageTitle.value))
</script> </script>