Skip to content

Commit

Permalink
fix(task): dragging and dropping on mobile
Browse files Browse the repository at this point in the history
This change fixes a regression introduced in 1cbb93e.
In that change, the whole task area was made clickable using mouse events directly. Unfortunately, this also prevented the parent component of the task component to recieve them, essentially never getting notified about the mouse movement and thus never dragging the task. I don't know why this is only a problem on Safari, but it might be related to SortableJS/Sortable#1571 (comment)

Resolves https://community.vikunja.io/t/task-re-ordering-is-not-working-in-safari/1916
Resolves https://kolaente.dev/vikunja/vikunja/issues/2092
Resolves #304
  • Loading branch information
kolaente committed Sep 18, 2024
1 parent f4d6285 commit abf92e2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
1 change: 1 addition & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ node_modules
dist
coverage
*.zip
.vite/

# Test files
cypress/screenshots
Expand Down
36 changes: 17 additions & 19 deletions frontend/src/components/tasks/partials/SingleTaskInProject.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<template>
<div>
<div
ref="taskContainerRef"
:class="{'is-loading': taskService.loading}"
class="task loader-container single-task"
tabindex="-1"
@mouseup.stop.self="openTaskDetail"
@mousedown.stop.self="focusTaskLink"
@click="openTaskDetail"
@keyup.enter="openTaskDetail"
>
<FancyCheckbox
v-model="task.done"
:disabled="(isArchived || disabled) && !canMarkAsDone"
@update:modelValue="markAsDone"
@click.stop
/>

<ColorBubble
Expand All @@ -23,8 +23,6 @@
<div
:class="{ 'done': task.done, 'show-project': showProject && project}"
class="tasktext"
@mouseup.stop.self="openTaskDetail"
@mousedown.stop.self="focusTaskLink"
>
<span>
<RouterLink
Expand All @@ -33,6 +31,7 @@
:to="{ name: 'project.index', params: { projectId: task.projectId } }"
class="task-project mr-1"
:class="{'mr-2': task.hexColor !== ''}"
@click.stop
>
{{ project.title }}
</RouterLink>
Expand All @@ -42,15 +41,15 @@
:color="getHexColor(task.hexColor)"
class="mr-1"
/>
<PriorityLabel
:priority="task.priority"
:done="task.done"
class="pr-2"
/>
<RouterLink
ref="taskLink"
ref="taskLinkRef"
:to="taskDetailRoute"
class="task-link"
tabindex="-1"
Expand Down Expand Up @@ -141,14 +140,15 @@
v-tooltip="$t('task.detail.belongsToProject', {project: project.title})"
:to="{ name: 'project.index', params: { projectId: task.projectId } }"
class="task-project"
@click.stop
>
{{ project.title }}
</RouterLink>
<BaseButton
:class="{'is-favorite': task.isFavorite}"
class="favorite"
@click="toggleFavorite"
@click.stop="toggleFavorite"
>
<Icon
v-if="task.isFavorite"
Expand Down Expand Up @@ -343,24 +343,22 @@ async function toggleFavorite() {
emit('taskUpdated', task.value)
}
const taskLink = ref<HTMLElement | null>(null)
const taskContainerRef = ref<HTMLElement | null>(null)
const taskLinkRef = ref<HTMLElement | null>(null)
function hasTextSelected() {
const isTextSelected = window.getSelection().toString()
return !(typeof isTextSelected === 'undefined' || isTextSelected === '' || isTextSelected === '\n')
}
function openTaskDetail() {
if (!hasTextSelected()) {
taskLink.value.$el.click()
function openTaskDetail(event: MouseEvent | KeyboardEvent) {
if (event.target instanceof HTMLElement) {
const isInteractiveElement = event.target.closest('a, button, input, .favorite, [role="button"]')
if (isInteractiveElement || hasTextSelected()) {
return
}
}
}
function focusTaskLink() {
if (!hasTextSelected()) {
taskContainerRef.value.focus()
}
taskLinkRef.value?.$el.click()
}
</script>
Expand Down

0 comments on commit abf92e2

Please sign in to comment.