feat: add date math for filters #1342
|
@ -0,0 +1,10 @@
|
|||
// TODO: more ranges!
|
||||
konrad marked this conversation as resolved
Outdated
|
||||
export const dateRanges = {
|
||||
'task.show.today': ['now/d', 'now/d+1d'],
|
||||
'task.show.thisWeek': ['now/w', 'now/w+1w'],
|
||||
'task.show.nextWeek': ['now/w+1w', 'now/w+2w'],
|
||||
'task.show.next7Days': ['now', 'now+7d'],
|
||||
'task.show.thisMonth': ['now/M', 'now/M+1M'],
|
||||
'task.show.nextMonth': ['now/M+1M', 'now/M+2M'],
|
||||
'task.show.next30Days': ['now', 'now+30d'],
|
||||
}
|
|
@ -59,11 +59,12 @@
|
|||
<script lang="ts" setup>
|
||||
import flatPickr from 'vue-flatpickr-component'
|
||||
import 'flatpickr/dist/flatpickr.css'
|
||||
import {computed, Ref, ref, watch} from 'vue'
|
||||
import {computed, ref, watch} from 'vue'
|
||||
import {useI18n} from 'vue-i18n'
|
||||
import {store} from '@/store'
|
||||
import {format} from 'date-fns'
|
||||
import Popup from '@/components/misc/popup'
|
||||
import Popup from '@/components/misc/popup.vue'
|
||||
konrad marked this conversation as resolved
Outdated
dpschen
commented
The whole explanation card should be its own component. The whole explanation card should be its own component.
konrad
commented
Done! Done!
|
||||
|
||||
import {dateRanges} from '@/components/date/dateRanges'
|
||||
|
||||
const {t} = useI18n()
|
||||
|
||||
|
@ -135,16 +136,6 @@ function setDateRange(range: string[] | null) {
|
|||
inputChanged()
|
||||
}
|
||||
|
||||
const dateRanges = {
|
||||
'task.show.today': ['now/d', 'now/d+1d'],
|
||||
'task.show.thisWeek': ['now/w', 'now/w+1w'],
|
||||
'task.show.nextWeek': ['now/w+1w', 'now/w+2w'],
|
||||
'task.show.next7Days': ['now', 'now+7d'],
|
||||
'task.show.thisMonth': ['now/M', 'now/M+1M'],
|
||||
'task.show.nextMonth': ['now/M+1M', 'now/M+2M'],
|
||||
'task.show.next30Days': ['now', 'now+30d'],
|
||||
}
|
||||
|
||||
const customRangeActive = computed<Boolean>(() => {
|
||||
dpschen
commented
This is triggered three times! Once for each of these lines:
in the called function inputChanged of the watcher. This is triggered three times!
Once for each of these lines:
```js
from.value = fromDate
to.value = toDate
```
in the called function inputChanged of the watcher.
And then here again.
konrad
commented
mhh how can we fix this? Using a debounce to prevent it getting called three times if it changed all values at once? Or removing the watchers again? It looks like the tasks are only loaded once, not three times. Maybe that's already enough? mhh how can we fix this? Using a debounce to prevent it getting called three times if it changed all values at once? Or removing the watchers again?
It looks like the tasks are only loaded once, not three times. Maybe that's already enough?
|
||||
return !Object.values(dateRanges).some(el => from.value === el[0] && to.value === el[1])
|
||||
})
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import {dateRanges} from '@/components/date/dateRanges'
|
||||
import SingleTaskInList from '@/components/tasks/partials/singleTaskInList'
|
||||
import {mapState} from 'vuex'
|
||||
|
||||
|
@ -106,12 +107,19 @@ export default {
|
|||
return this.$route.query.showOverdue === 'true'
|
||||
},
|
||||
pageTitle() {
|
||||
const title = this.showAll
|
||||
? this.$t('task.show.titleCurrent')
|
||||
: this.$t('task.show.fromuntil', {
|
||||
from: this.format(this.dateFrom, 'PPP'),
|
||||
until: this.format(this.dateTo, 'PPP'),
|
||||
})
|
||||
let title = ''
|
||||
|
||||
const predefinedRange = Object.entries(dateRanges).find(([key, value]) => this.dateFrom === value[0] && this.dateTo === value[1])
|
||||
if (typeof predefinedRange !== 'undefined') {
|
||||
title = this.$t(predefinedRange[0])
|
||||
} else {
|
||||
konrad marked this conversation as resolved
Outdated
dpschen
commented
This is a sideeffect inside a computed. Remove this.
This is a sideeffect inside a computed. Remove this.
Better watch the computed and react to that:
```js
watchEffect(() => setTitle(pageTitle.value))
```
konrad
commented
Done. Done.
|
||||
title = this.showAll
|
||||
? this.$t('task.show.titleCurrent')
|
||||
: this.$t('task.show.fromuntil', {
|
||||
from: this.format(this.dateFrom, 'PPP'),
|
||||
until: this.format(this.dateTo, 'PPP'),
|
||||
})
|
||||
}
|
||||
|
||||
this.setTitle(title)
|
||||
|
||||
|
|
Reference in New Issue
Use UPPER_SNAKE_CASE for constants
Done.