Skip to content

TaskView is a self-hosted project and task management platform focused on clarity, ownership, and control. TaskView is built for teams that want a transparent, self-hosted alternative to SaaS task managers.

feat(web): reschedule calendar tasks by drag and drop

Daniel Barreto534feae9f205
diff --git a/web/src/components/features/calendar/CalendarTaskCard.vue b/web/src/components/features/calendar/CalendarTaskCard.vue
index 3c3b2aa..672842c 100644
--- a/web/src/components/features/calendar/CalendarTaskCard.vue
+++ b/web/src/components/features/calendar/CalendarTaskCard.vue
@@ -9,8 +9,8 @@
/>
<div
v-else
- class="tv-calendar-card flex w-full min-w-0 items-start gap-1.5 rounded-10 border px-1.5 py-1 text-sm text-default"
- :class="{ 'opacity-60': task.complete }"
+ class="tv-calendar-card group relative flex w-full min-w-0 items-start gap-1.5 rounded-10 border px-1.5 py-1 text-sm text-default"
+ :class="{ 'opacity-60': task.complete && !lifted, 'pr-3': resizable, 'shadow-lg': lifted }"
:style="{ backgroundColor: tint.backgroundColor, borderColor: tint.borderColor }"
:data-testid="`calendar-task-${task.id}`"
>
@@ -51,6 +51,13 @@
/>
{{ task.subtasks.length }}
</span>
+
+ <!-- Only a hint: FullCalendar's own resize handle sits on top of it and takes the pointer -->
+ <span
+ v-if="resizable"
+ class="pointer-events-none absolute inset-y-1.5 right-1 w-1 rounded-full bg-current opacity-0 transition-opacity group-hover:opacity-40"
+ aria-hidden="true"
+ />
</div>
</template>
@@ -68,6 +75,10 @@ const props = defineProps<{
compact?: boolean
// Phone-width month: cells are too narrow for text, show a priority-colored bar
dot?: boolean
+ // Its end can be dragged to change the duration: show a grip on hover
+ resizable?: boolean
+ // The copy that follows the pointer while dragging
+ lifted?: boolean
}>()
const { t } = useI18n()
diff --git a/web/src/components/features/calendar/ProjectCalendar.vue b/web/src/components/features/calendar/ProjectCalendar.vue
index 627daf6..424b64d 100644
--- a/web/src/components/features/calendar/ProjectCalendar.vue
+++ b/web/src/components/features/calendar/ProjectCalendar.vue
@@ -48,6 +48,8 @@
:time-text="arg.event.allDay ? undefined : arg.timeText"
:compact="arg.view.type !== FC_VIEWS.week"
:dot="isMobile && arg.view.type === FC_VIEWS.month"
+ :resizable="arg.isEndResizable"
+ :lifted="arg.isMirror"
/>
</template>
</FullCalendar>
@@ -79,8 +81,9 @@ import { computed, ref, useTemplateRef, watch } from 'vue'
import { addDays, eachDayOfInterval, getDay, isWeekend } from 'date-fns'
import { useI18n } from 'vue-i18n'
import FullCalendar from '@fullcalendar/vue3'
-import type { CalendarOptions, DatesSetInfo, EventClickInfo } from '@fullcalendar/vue3'
+import type { CalendarOptions, DatesSetInfo, EventChangeInfo, EventClickInfo, EventDropInfo, EventResizeDoneInfo } from '@fullcalendar/vue3'
import dayGridPlugin from '@fullcalendar/vue3/daygrid'
+import interactionPlugin from '@fullcalendar/vue3/interaction'
import listPlugin from '@fullcalendar/vue3/list'
import classicThemePlugin from '@fullcalendar/vue3/themes/classic'
import deLocale from '@fullcalendar/vue3/locales/de'
@@ -93,11 +96,12 @@ import '@/assets/css/calendar.css'
import CalendarToolbar from './CalendarToolbar.vue'
import CalendarTaskCard from './CalendarTaskCard.vue'
import { useCalendarStore } from '@/stores/calendar.store'
+import { useGoalPermissions } from '@/composables/useGoalPermissions'
import { useTaskDetailPanel } from '@/composables/useTaskDetailPanel'
import { useTaskView } from '@/composables/useTaskView'
import { useWeekStart } from '@/composables/useWeekStart'
import { useCalendarRouteState, type CalendarView } from '@/composables/useCalendarRouteState'
-import { isScheduled, occupiesDay, taskToEvent, type TaskCalendarEvent } from '@/helpers/taskCalendarDates'
+import { isScheduled, occupiesDay, shiftTaskDates, taskToEvent, type TaskCalendarEvent } from '@/helpers/taskCalendarDates'
const props = defineProps<{ goalId: number }>()
@@ -111,6 +115,8 @@ const { t, locale } = useI18n()
const calendarStore = useCalendarStore()
const { openTask } = useTaskDetailPanel()
const { isMobile } = useTaskView()
+const { canEditTaskDeadline } = useGoalPermissions()
+const toast = useToast()
const weekStart = useWeekStart()
const { view, date } = useCalendarRouteState(isMobile.value ? 'list' : 'week')
@@ -130,9 +136,11 @@ const events = computed(() => calendarStore.tasks
// Like Asana, an empty Saturday or Sunday shrinks to a narrow column in the week view.
// Only empty days collapse, so no multi-day bar ever spans a column narrower than the rest.
+// Only when tasks can't be moved: FullCalendar finds the day under the pointer assuming equal-width
+// columns, so a narrow column would make drops and resizes land on the wrong day.
const visibleRange = ref<{ start: Date; end: Date }>()
const collapsedWeekdays = computed(() => {
- if (!visibleRange.value) return new Set<number>()
+ if (!visibleRange.value || canEditTaskDeadline.value) return new Set<number>()
const { start, end } = visibleRange.value
const emptyWeekendDays = eachDayOfInterval({ start, end: addDays(end, -1) })
.filter((day) => isWeekend(day) && !events.value.some((event) => occupiesDay(event, day)))
@@ -164,8 +172,25 @@ function onEventClick(info: EventClickInfo) {
openTask((info.event.extendedProps.task as TaskCalendarEvent['extendedProps']['task']).id)
}
+// FullCalendar has already moved the event: save the shift and put the event back if that fails.
+// Day grids move events by whole days, so the deltas carry days only.
+async function saveShift(info: EventChangeInfo, startDays: number, endDays: number) {
+ const { task } = info.event.extendedProps as TaskCalendarEvent['extendedProps']
+ if (await calendarStore.updateTaskDates(shiftTaskDates(task, startDays, endDays))) return
+ info.revert()
+ toast.add({ title: t('calendar.moveError'), color: 'error' })
+}
+
+function onEventDrop(info: EventDropInfo) {
+ saveShift(info, info.delta.days, info.delta.days)
+}
+
+function onEventResize(info: EventResizeDoneInfo) {
+ saveShift(info, info.startDelta.days, info.endDelta.days)
+}
+
const calendarOptions = computed<CalendarOptions>(() => ({
- plugins: [classicThemePlugin, dayGridPlugin, listPlugin],
+ plugins: [classicThemePlugin, dayGridPlugin, interactionPlugin, listPlugin],
initialView,
initialDate,
headerToolbar: false,
@@ -187,5 +212,8 @@ const calendarOptions = computed<CalendarOptions>(() => ({
},
datesSet: onDatesSet,
eventClick: onEventClick,
+ editable: canEditTaskDeadline.value,
+ eventDrop: onEventDrop,
+ eventResize: onEventResize,
}))
</script>
diff --git a/web/src/helpers/taskCalendarDates.ts b/web/src/helpers/taskCalendarDates.ts
index 62e49bc..100b50a 100644
--- a/web/src/helpers/taskCalendarDates.ts
+++ b/web/src/helpers/taskCalendarDates.ts
@@ -1,5 +1,5 @@
import { addDays, format } from 'date-fns'
-import type { Task } from 'taskview-api'
+import type { Task, TaskArgUpdate } from 'taskview-api'
// Which task fields a single-day event was built from, so later writes can target the same field
export type TaskDateShape = 'range' | 'start' | 'end'
@@ -54,6 +54,47 @@ export function taskToEvent(task: Task): TaskCalendarEvent | null {
: { ...base, start: date, allDay: true, extendedProps: { task, shape } }
}
+// A stored date moved by whole local days. A UTC time is shifted in local time,
+// so 09:00 stays 09:00 even across a daylight saving change.
+function shiftDay(date: string, time: string | null | undefined, days: number): { date: string; time: string | null } {
+ if (!time) return { date: format(addDays(new Date(`${date}T00:00:00`), days), DAY_FORMAT), time: null }
+ const iso = addDays(utcDateTime(date, time), days).toISOString()
+ return { date: iso.slice(0, 10), time: `${iso.slice(11, 16)}:00` }
+}
+
+/**
+ * The dates to save after a task's event is moved or resized by whole days. Times and the fields
+ * that are set are kept; a single date only becomes a range when its two ends move apart, and a
+ * date-only range shrunk to one day goes back to a single date.
+ */
+export function shiftTaskDates(task: Task, startDays: number, endDays: number): TaskArgUpdate {
+ const { id, startDate, startTime, endDate, endTime } = task
+
+ if (startDate && endDate) {
+ const start = shiftDay(startDate, startTime, startDays)
+ const end = shiftDay(endDate, endTime, endDays)
+ // Resized down to one day: a date-only range becomes a single date (the deadline, as the date
+ // picker stores it). Moves keep the range, and a range with times stays, as it holds two times.
+ if (startDays !== endDays && start.date === end.date && !start.time && !end.time) {
+ return { id, startDate: null, startTime: null, endDate: end.date, endTime: null }
+ }
+ return { id, startDate: start.date, startTime: start.time, endDate: end.date, endTime: end.time }
+ }
+
+ const date = (startDate ?? endDate)!
+ const time = startDate ? startTime : endTime
+ if (startDays !== endDays) {
+ const start = shiftDay(date, time, startDays)
+ const end = shiftDay(date, time, endDays)
+ return { id, startDate: start.date, startTime: start.time, endDate: end.date, endTime: end.time }
+ }
+
+ const moved = shiftDay(date, time, startDays)
+ return startDate
+ ? { id, startDate: moved.date, startTime: moved.time }
+ : { id, endDate: moved.date, endTime: moved.time }
+}
+
function toLocalDate(value: string | Date): Date {
return typeof value === 'string' ? new Date(`${value}T00:00:00`) : value
}
diff --git a/web/src/locales/de.ts b/web/src/locales/de.ts
index 5a58960..f86d5e9 100644
--- a/web/src/locales/de.ts
+++ b/web/src/locales/de.ts
@@ -295,6 +295,7 @@ export default {
list: 'Liste',
},
subtasks: 'Unteraufgaben: {count}',
+ moveError: 'Die neuen Termine konnten nicht gespeichert werden. Die Aufgabe ist wieder an ihrem Platz.',
empty: {
title: 'Hier erscheinen Aufgaben mit Datum',
description: 'Öffnen Sie eine Aufgabe und legen Sie ein Start- oder Enddatum fest, um sie im Kalender zu sehen.',
diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts
index 5d80c1d..0b0f829 100644
--- a/web/src/locales/en.ts
+++ b/web/src/locales/en.ts
@@ -309,6 +309,7 @@ export default {
list: 'List',
},
subtasks: 'Subtasks: {count}',
+ moveError: 'Couldn\'t save the new dates. The task is back where it was.',
empty: {
title: 'Tasks with dates appear here',
description: 'Open a task and set a start or end date to see it on the calendar.',
diff --git a/web/src/locales/es.ts b/web/src/locales/es.ts
index e57281e..4ae1c57 100644
--- a/web/src/locales/es.ts
+++ b/web/src/locales/es.ts
@@ -295,6 +295,7 @@ export default {
list: 'Lista',
},
subtasks: 'Subtareas: {count}',
+ moveError: 'No se pudieron guardar las fechas nuevas. La tarea volvió a su lugar.',
empty: {
title: 'Aquí aparecen las tareas con fecha',
description: 'Abre una tarea y ponle fecha de inicio o de fin para verla en el calendario.',
diff --git a/web/src/locales/pt-br.ts b/web/src/locales/pt-br.ts
index 9962fd7..7c6d139 100644
--- a/web/src/locales/pt-br.ts
+++ b/web/src/locales/pt-br.ts
@@ -308,6 +308,7 @@ export default {
list: 'Lista',
},
subtasks: 'Subtarefas: {count}',
+ moveError: 'Não foi possível salvar as novas datas. A tarefa voltou ao lugar.',
empty: {
title: 'Aqui aparecem as tarefas com data',
description: 'Abra uma tarefa e defina uma data de início ou de término para vê-la no calendário.',
diff --git a/web/src/locales/ru.ts b/web/src/locales/ru.ts
index 03439b7..a51c535 100644
--- a/web/src/locales/ru.ts
+++ b/web/src/locales/ru.ts
@@ -309,6 +309,7 @@ export default {
list: 'Список',
},
subtasks: 'Подзадачи: {count}',
+ moveError: 'Не удалось сохранить новые даты. Задача вернулась на прежнее место.',
empty: {
title: 'Здесь появляются задачи с датой',
description: 'Откройте задачу и укажите дату начала или окончания, чтобы увидеть её в календаре.',
diff --git a/web/src/stores/calendar.store.ts b/web/src/stores/calendar.store.ts
index b04d0d6..6f95d91 100644
--- a/web/src/stores/calendar.store.ts
+++ b/web/src/stores/calendar.store.ts
@@ -1,7 +1,8 @@
import { defineStore } from 'pinia'
-import { ALL_TASKS_LIST_ID, type GoalItem } from 'taskview-api'
+import { ALL_TASKS_LIST_ID, type GoalItem, type TaskArgUpdate } from 'taskview-api'
import { $tvApi } from '@/plugins/axios'
import { logError } from '@/helpers/Helper'
+import { useTasksStore } from '@/stores/tasks.store'
import type { TaskItem } from '@/types/tasks.types'
type CalendarStore = {
@@ -11,6 +12,8 @@ type CalendarStore = {
}
let latestRequest = 0
+// Per task, the latest date update: an older response must not undo a newer move
+const latestDateUpdate = new Map<number, number>()
export const useCalendarStore = defineStore('use-calendar-store', {
state: (): CalendarStore => ({
@@ -47,6 +50,30 @@ export const useCalendarStore = defineStore('use-calendar-store', {
if (tasks) this.tasks = tasks
},
+ // Applied right away, as FullCalendar already shows the move: a second drag before the response
+ // must start from these dates. Returns null when the update fails, so the caller can put the event back.
+ async updateTaskDates(patch: TaskArgUpdate) {
+ const local = this.tasks.find((t) => t.id === patch.id)
+ const fields = Object.keys(patch) as (keyof TaskArgUpdate)[]
+ const previous = local && Object.fromEntries(fields.map((field) => [field, local[field as keyof TaskItem]]))
+ if (local) Object.assign(local, patch)
+
+ const request = (latestDateUpdate.get(patch.id) ?? 0) + 1
+ latestDateUpdate.set(patch.id, request)
+ const task = await $tvApi.tasks.updateTask(patch).catch(logError)
+ const isLatest = latestDateUpdate.get(patch.id) === request
+
+ if (!task) {
+ if (isLatest && local && previous) Object.assign(local, previous)
+ return null
+ }
+ if (isLatest) {
+ this.syncTask(task)
+ useTasksStore().updateSelectedTask(task)
+ }
+ return task
+ },
+
syncTask(task: TaskItem) {
const local = this.tasks.find((t) => t.id === task.id)
if (local) Object.assign(local, task)