feat: use withDefaults for Reminders
(cherry picked from commit 6990be705c6d47047147dea2930196246f1e2885)
This commit is contained in:
parent
eee895105a
commit
8729c24e1d
@ -3,7 +3,7 @@
|
|||||||
<div
|
<div
|
||||||
v-for="(r, index) in reminders"
|
v-for="(r, index) in reminders"
|
||||||
:key="index"
|
:key="index"
|
||||||
:class="{ 'overdue': r.reminder < new Date() }"
|
:class="{ 'overdue': r.reminder < now }"
|
||||||
class="reminder-input"
|
class="reminder-input"
|
||||||
>
|
>
|
||||||
<ReminderDetail
|
<ReminderDetail
|
||||||
@ -40,21 +40,25 @@ import BaseButton from '@/components/base/BaseButton.vue'
|
|||||||
import ReminderDetail from '@/components/tasks/partials/ReminderDetail.vue'
|
import ReminderDetail from '@/components/tasks/partials/ReminderDetail.vue'
|
||||||
import type {ITask} from '@/modelTypes/ITask'
|
import type {ITask} from '@/modelTypes/ITask'
|
||||||
import {REMINDER_PERIOD_RELATIVE_TO_TYPES} from '@/types/IReminderPeriodRelativeTo'
|
import {REMINDER_PERIOD_RELATIVE_TO_TYPES} from '@/types/IReminderPeriodRelativeTo'
|
||||||
|
import { useNow } from '@vueuse/core'
|
||||||
|
|
||||||
const {
|
const props = withDefaults(defineProps<{
|
||||||
modelValue,
|
|
||||||
disabled = false,
|
|
||||||
} = defineProps<{
|
|
||||||
modelValue: ITask,
|
modelValue: ITask,
|
||||||
disabled?: boolean,
|
disabled?: boolean,
|
||||||
}>()
|
}>(), {
|
||||||
|
disabled: false,
|
||||||
|
})
|
||||||
|
|
||||||
const emit = defineEmits(['update:modelValue'])
|
const emit = defineEmits<{
|
||||||
|
'update:modelValue': [ITask]
|
||||||
|
}>()
|
||||||
|
|
||||||
const reminders = ref<ITaskReminder[]>([])
|
const reminders = ref<ITaskReminder[]>([])
|
||||||
|
|
||||||
|
const now = useNow({interval: 1000})
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => modelValue.reminders,
|
() => props.modelValue.reminders,
|
||||||
(newVal) => {
|
(newVal) => {
|
||||||
reminders.value = newVal
|
reminders.value = newVal
|
||||||
},
|
},
|
||||||
@ -62,19 +66,19 @@ watch(
|
|||||||
)
|
)
|
||||||
|
|
||||||
const defaultRelativeTo = computed(() => {
|
const defaultRelativeTo = computed(() => {
|
||||||
if (typeof modelValue === 'undefined') {
|
if (typeof props.modelValue === 'undefined') {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modelValue?.dueDate) {
|
if (props.modelValue?.dueDate) {
|
||||||
return REMINDER_PERIOD_RELATIVE_TO_TYPES.DUEDATE
|
return REMINDER_PERIOD_RELATIVE_TO_TYPES.DUEDATE
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modelValue.dueDate === null && modelValue.startDate !== null) {
|
if (props.modelValue.dueDate === null && props.modelValue.startDate !== null) {
|
||||||
return REMINDER_PERIOD_RELATIVE_TO_TYPES.STARTDATE
|
return REMINDER_PERIOD_RELATIVE_TO_TYPES.STARTDATE
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modelValue.dueDate === null && modelValue.startDate === null && modelValue.endDate !== null) {
|
if (props.modelValue.dueDate === null && props.modelValue.startDate === null && props.modelValue.endDate !== null) {
|
||||||
return REMINDER_PERIOD_RELATIVE_TO_TYPES.ENDDATE
|
return REMINDER_PERIOD_RELATIVE_TO_TYPES.ENDDATE
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +87,7 @@ const defaultRelativeTo = computed(() => {
|
|||||||
|
|
||||||
function updateData() {
|
function updateData() {
|
||||||
emit('update:modelValue', {
|
emit('update:modelValue', {
|
||||||
...modelValue,
|
...props.modelValue,
|
||||||
reminders: reminders.value,
|
reminders: reminders.value,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user