|
80 | 80 | </div> |
81 | 81 | </ERSection> |
82 | 82 |
|
| 83 | + <!-- Schedule mode (only for non-recurring) --> |
| 84 | + <ERSection v-if="draft.frequency === 'NONE'" label="Schedule"> |
| 85 | + <label class="flex items-center gap-2 rounded-card border border-line bg-surface-sunken px-3 py-2.5 text-sm text-ink cursor-pointer"> |
| 86 | + <input |
| 87 | + v-model="draft.unscheduled" |
| 88 | + type="checkbox" |
| 89 | + class="h-4 w-4 accent-brand" |
| 90 | + /> |
| 91 | + <span class="flex-1">Unscheduled (no specific date/time)</span> |
| 92 | + </label> |
| 93 | + </ERSection> |
| 94 | + |
| 95 | + <!-- Date (non-recurring + scheduled) --> |
| 96 | + <ERSection |
| 97 | + v-if="draft.frequency === 'NONE' && !draft.unscheduled" |
| 98 | + label="Date" |
| 99 | + > |
| 100 | + <input |
| 101 | + v-model="draft.scheduledDate" |
| 102 | + type="date" |
| 103 | + class="w-full rounded-card border border-line bg-surface-sunken px-3.5 py-2.5 text-sm text-ink outline-none focus:border-line-strong" |
| 104 | + /> |
| 105 | + </ERSection> |
| 106 | + |
83 | 107 | <!-- Time + Duration --> |
84 | | - <div class="grid grid-cols-2 gap-2.5"> |
| 108 | + <div |
| 109 | + v-if="!(draft.frequency === 'NONE' && draft.unscheduled)" |
| 110 | + class="grid grid-cols-2 gap-2.5" |
| 111 | + > |
85 | 112 | <ERSection label="Time"> |
86 | 113 | <div class="flex items-center gap-1.5 rounded-card border border-line bg-surface-sunken px-3 py-2.5"> |
87 | 114 | <DRIcon name="clock" :size="13" :stroke="catColor" /> |
|
283 | 310 | dayOfMonth: number; |
284 | 311 | month: number; |
285 | 312 | reminderMin: number | null; |
| 313 | + unscheduled: boolean; |
| 314 | + scheduledDate: string; |
286 | 315 | } |
287 | 316 |
|
288 | 317 | const props = defineProps<{ |
|
297 | 326 |
|
298 | 327 | const titleRef = ref<HTMLInputElement | null>(null); |
299 | 328 |
|
| 329 | + function todayIso(): string { |
| 330 | + const d = new Date(); |
| 331 | + const y = d.getFullYear(); |
| 332 | + const m = String(d.getMonth() + 1).padStart(2, '0'); |
| 333 | + const day = String(d.getDate()).padStart(2, '0'); |
| 334 | + return `${y}-${m}-${day}`; |
| 335 | + } |
| 336 | +
|
| 337 | + function parseTimeStr(s: any): { h: number; m: number } | null { |
| 338 | + if (typeof s !== 'string') return null; |
| 339 | + const parts = s.split(':'); |
| 340 | + if (parts.length < 2) return null; |
| 341 | + const h = parseInt(parts[0], 10); |
| 342 | + const m = parseInt(parts[1], 10); |
| 343 | + if (isNaN(h) || isNaN(m)) return null; |
| 344 | + return { h, m }; |
| 345 | + } |
| 346 | +
|
| 347 | + const r = props.routine ?? {}; |
| 348 | + const initialFreq = (r.recurrence?.frequency ?? r.frequency ?? 'NONE') as RoutineFrequency; |
| 349 | + const taskTime = parseTimeStr(r.scheduled_time); |
| 350 | + const hasTime = |
| 351 | + r.time?.h != null || |
| 352 | + r.recurrence?.time?.hours != null || |
| 353 | + taskTime !== null; |
| 354 | + const hasDate = !!(r.scheduled_date || r._draftDate); |
| 355 | + const isExistingNone = r.id != null && initialFreq === 'NONE'; |
| 356 | +
|
300 | 357 | const initial: RoutineDraft = { |
301 | | - id: props.routine?.id ?? null, |
302 | | - title: props.routine?.title ?? '', |
303 | | - description: props.routine?.description ?? '', |
304 | | - cat: (props.routine?.routine_category?.id ?? props.routine?.cat ?? 'none') as RoutineCategoryId, |
305 | | - timeH: props.routine?.time?.h ?? props.routine?.recurrence?.time?.hours ?? 9, |
306 | | - timeM: props.routine?.time?.m ?? props.routine?.recurrence?.time?.minutes ?? 0, |
307 | | - durationMin: props.routine?.recurrence?.duration_min ?? props.routine?.durationMin ?? 30, |
308 | | - frequency: (props.routine?.recurrence?.frequency ?? props.routine?.frequency ?? 'NONE') as RoutineFrequency, |
309 | | - interval: props.routine?.recurrence?.interval ?? 1, |
310 | | - daysOfWeek: dowsToIndices(props.routine?.recurrence?.days_of_week ?? []), |
311 | | - dayOfMonth: props.routine?.recurrence?.day_of_frequency ?? new Date().getDate(), |
312 | | - month: props.routine?.recurrence?.month ?? 0, |
313 | | - reminderMin: props.routine?.recurrence?.reminder_min ?? null, |
| 358 | + id: r.id ?? null, |
| 359 | + title: r.title ?? '', |
| 360 | + description: r.description ?? '', |
| 361 | + cat: (r.routine_category?.id ?? r.cat ?? 'none') as RoutineCategoryId, |
| 362 | + timeH: r.time?.h ?? r.recurrence?.time?.hours ?? taskTime?.h ?? 9, |
| 363 | + timeM: r.time?.m ?? r.recurrence?.time?.minutes ?? taskTime?.m ?? 0, |
| 364 | + durationMin: r.recurrence?.duration_min ?? r.durationMin ?? 30, |
| 365 | + frequency: initialFreq, |
| 366 | + interval: r.recurrence?.interval ?? 1, |
| 367 | + daysOfWeek: dowsToIndices(r.recurrence?.days_of_week ?? []), |
| 368 | + dayOfMonth: r.recurrence?.day_of_frequency ?? new Date().getDate(), |
| 369 | + month: r.recurrence?.month ?? 0, |
| 370 | + reminderMin: r.recurrence?.reminder_min ?? null, |
| 371 | + unscheduled: isExistingNone ? !hasTime && !hasDate : false, |
| 372 | + scheduledDate: r.scheduled_date ?? r._draftDate ?? r.date ?? todayIso(), |
314 | 373 | }; |
315 | 374 |
|
316 | 375 | const draft = reactive<RoutineDraft>(initial); |
|
0 commit comments