Skip to content

Commit 2dd24ae

Browse files
committed
feat(routines): resize routine blocks in the day view
Add top/bottom drag handles to day-view routine blocks: the bottom edge changes duration, the top edge shifts the start time (both snap to 15 min). Duration persists via a partial task update (approximately_time); start reuses the move plumbing. Also add 120m/180m duration presets to the edit modal.
1 parent cce27d9 commit 2dd24ae

4 files changed

Lines changed: 100 additions & 7 deletions

File tree

‎src/components/dailyRoutine/EditRoutineModal.vue‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
<div class="flex-1" />
146146
<div class="flex gap-0.5">
147147
<button
148-
v-for="p in [15, 30, 45, 60, 90]"
148+
v-for="p in [15, 30, 45, 60, 90, 120, 180]"
149149
:key="p"
150150
type="button"
151151
class="rounded-md px-1.5 py-1 text-[10px] font-semibold transition-colors"

‎src/components/dailyRoutine/EventBlock.vue‎

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div
3-
class="dr-week-chip absolute cursor-pointer overflow-hidden rounded-md transition-opacity"
3+
class="dr-week-chip group absolute cursor-pointer overflow-hidden rounded-md transition-opacity"
44
:class="[
55
entry.completed ? 'opacity-50' : 'opacity-100',
66
isBeingDragged ? 'opacity-30' : '',
@@ -41,17 +41,35 @@
4141
>
4242
<DRIcon name="pencil" :size="9" stroke="rgba(255,255,255,.85)" />
4343
</button>
44+
45+
<!-- Resize handles: top edge shifts the start, bottom edge changes the duration -->
46+
<div
47+
v-if="canResize"
48+
class="dr-resize-handle absolute inset-x-0 top-0 h-2 cursor-ns-resize opacity-0 transition-opacity group-hover:opacity-100 after:absolute after:inset-x-3 after:top-[2px] after:h-[2px] after:rounded-full after:bg-current after:opacity-40 after:content-['']"
49+
title="Drag to change start time"
50+
@pointerdown.stop.prevent="onResizeStart($event, 'top')"
51+
@click.stop
52+
/>
53+
<div
54+
v-if="canResize"
55+
class="dr-resize-handle absolute inset-x-0 bottom-0 h-2 cursor-ns-resize opacity-0 transition-opacity group-hover:opacity-100 after:absolute after:inset-x-3 after:bottom-[2px] after:h-[2px] after:rounded-full after:bg-current after:opacity-40 after:content-['']"
56+
title="Drag to change duration"
57+
@pointerdown.stop.prevent="onResizeStart($event, 'bottom')"
58+
@click.stop
59+
/>
4460
</div>
4561
</template>
4662

4763
<script setup lang="ts">
48-
import { computed } from 'vue';
64+
import { computed, ref } from 'vue';
4965
import DRIcon from './DRIcon.vue';
5066
import { hexAlpha, resolveCategory } from '@/utils/dailyRoutines/categoryMap';
5167
import { fmtTime } from '@/utils/dailyRoutines/dateHelpers';
5268
import type { RoutineEntry } from '@/types/dailyRoutine';
5369
5470
const HOUR_PX = 56;
71+
const SNAP_MIN = 15;
72+
const MIN_DURATION = 15;
5573
5674
import { useRoutineDrag } from '@/composable/useRoutineDrag';
5775
@@ -66,6 +84,7 @@
6684
(e: 'toggle', entry: RoutineEntry): void;
6785
(e: 'edit', entry: RoutineEntry): void;
6886
(e: 'context', payload: { entry: RoutineEntry; x: number; y: number }): void;
87+
(e: 'resize', payload: { entry: RoutineEntry; startMin: number; endMin: number }): void;
6988
}>();
7089
7190
const { active, onPointerDown } = useRoutineDrag();
@@ -81,8 +100,51 @@
81100
emit('toggle', props.entry);
82101
}
83102
84-
const top = computed(() => (props.startMin / 60) * HOUR_PX);
85-
const height = computed(() => Math.max(24, ((props.endMin - props.startMin) / 60) * HOUR_PX - 2));
103+
// ── resize (drag top/bottom edge) ──────────────────────────────────────────
104+
// Only full day-view blocks are resizable; stacked/compact ones are not.
105+
const canResize = computed(() => props.mode === 'full');
106+
const resizePreview = ref<{ startMin: number; endMin: number } | null>(null);
107+
const effStartMin = computed(() => resizePreview.value?.startMin ?? props.startMin);
108+
const effEndMin = computed(() => resizePreview.value?.endMin ?? props.endMin);
109+
110+
function snap(min: number): number {
111+
return Math.round(min / SNAP_MIN) * SNAP_MIN;
112+
}
113+
114+
function onResizeStart(e: PointerEvent, edge: 'top' | 'bottom') {
115+
const startY = e.clientY;
116+
const origStart = props.startMin;
117+
const origEnd = props.endMin;
118+
119+
const onMove = (ev: PointerEvent) => {
120+
const deltaMin = ((ev.clientY - startY) / HOUR_PX) * 60;
121+
if (edge === 'bottom') {
122+
const newEnd = Math.min(24 * 60, Math.max(origStart + MIN_DURATION, snap(origEnd + deltaMin)));
123+
resizePreview.value = { startMin: origStart, endMin: newEnd };
124+
} else {
125+
const newStart = Math.max(0, Math.min(origEnd - MIN_DURATION, snap(origStart + deltaMin)));
126+
resizePreview.value = { startMin: newStart, endMin: origEnd };
127+
}
128+
};
129+
130+
const onUp = () => {
131+
document.removeEventListener('pointermove', onMove);
132+
document.removeEventListener('pointerup', onUp);
133+
document.removeEventListener('pointercancel', onUp);
134+
const preview = resizePreview.value;
135+
resizePreview.value = null;
136+
if (preview && (preview.startMin !== origStart || preview.endMin !== origEnd)) {
137+
emit('resize', { entry: props.entry, startMin: preview.startMin, endMin: preview.endMin });
138+
}
139+
};
140+
141+
document.addEventListener('pointermove', onMove);
142+
document.addEventListener('pointerup', onUp);
143+
document.addEventListener('pointercancel', onUp);
144+
}
145+
146+
const top = computed(() => (effStartMin.value / 60) * HOUR_PX);
147+
const height = computed(() => Math.max(24, ((effEndMin.value - effStartMin.value) / 60) * HOUR_PX - 2));
86148
const isShort = computed(() => height.value < 38);
87149
88150
const blockStyle = computed(() => {
@@ -108,8 +170,8 @@
108170
});
109171
110172
const endTimeStr = computed(() => {
111-
const h = Math.floor(props.endMin / 60) % 24;
112-
const m = props.endMin % 60;
173+
const h = Math.floor(effEndMin.value / 60) % 24;
174+
const m = effEndMin.value % 60;
113175
return fmtTime(h, m);
114176
});
115177
</script>

‎src/components/dailyRoutine/views/DayView.vue‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
@toggle="$emit('toggle', item.event.source.entry)"
102102
@edit="$emit('edit', item.event.source.entry)"
103103
@context="$emit('context', $event)"
104+
@resize="$emit('resize', $event)"
104105
/>
105106
</template>
106107
</div>
@@ -137,6 +138,7 @@
137138
(e: 'archive-done-unscheduled'): void;
138139
(e: 'create', payload: { date: string; timeH: number; timeM: number }): void;
139140
(e: 'context', payload: { entry: RoutineEntry; x: number; y: number }): void;
141+
(e: 'resize', payload: { entry: RoutineEntry; startMin: number; endMin: number }): void;
140142
}>();
141143
142144
function fmtIso(d: Date): string {

‎src/pages/DailyRoutine.vue‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@
225225
@create="onCreateAt"
226226
@select="onEdit"
227227
@context="onContext"
228+
@resize="onResizeRoutine"
228229
/>
229230
<WeekView
230231
v-else-if="view === 'week'"
@@ -315,6 +316,7 @@
315316
updateDailyTask,
316317
getDailyTask,
317318
} from '@/actions/tmgr/daily-tasks';
319+
import { updateTask } from '@/actions/tmgr/tasks';
318320
import ViewSwitcher from '@/components/dailyRoutine/ViewSwitcher.vue';
319321
import DRIcon from '@/components/dailyRoutine/DRIcon.vue';
320322
import CountChip from '@/components/dailyRoutine/CountChip.vue';
@@ -608,6 +610,9 @@
608610
duration_min: draft.durationMin,
609611
reminder_min: draft.reminderMin,
610612
};
613+
// Mirror duration onto the task so it stays the single source of truth
614+
// (day-view resize writes here too); the pattern's duration_min is legacy.
615+
payload.approximately_time = draft.durationMin;
611616
} else if (isUnscheduled) {
612617
payload.scheduled_date = null;
613618
payload.scheduled_time = null;
@@ -645,6 +650,30 @@
645650
await reload();
646651
}
647652
653+
// Drag the block's top/bottom edge in the day view: bottom changes duration,
654+
// top shifts the start time (and thus duration too).
655+
async function onResizeRoutine(payload: { entry: RoutineEntry; startMin: number; endMin: number }) {
656+
const { entry, startMin, endMin } = payload;
657+
const durationMin = Math.max(15, endMin - startMin);
658+
// Duration → task.approximately_time via a partial task update so
659+
// checkpoints/status/category are untouched. It's the single source of
660+
// truth the expander reads for the block height.
661+
await updateTask(entry.task_id, { approximately_time: durationMin } as any);
662+
// Top-edge drag also moved the start — reschedule that occurrence
663+
// (handles both one-off and recurring instances).
664+
const [origH, origM] = (entry.time ?? '00:00').split(':').map(Number);
665+
const origStartMin = (origH || 0) * 60 + (origM || 0);
666+
if (startMin !== origStartMin) {
667+
await store.dispatch('dailyRoutines/moveRoutine', {
668+
entry,
669+
date: entry.date,
670+
timeH: Math.floor(startMin / 60),
671+
timeM: startMin % 60,
672+
});
673+
}
674+
await reload();
675+
}
676+
648677
async function onDeleteRoutine(routine: any) {
649678
await store.dispatch('dailyRoutines/deleteRoutine', routine.id);
650679
editingRoutine.value = null;

0 commit comments

Comments
 (0)