5
11
Fork
You've already forked tomato
1

Drag and drop to reorder tasks #155

Merged
edwardloveall merged 1 commit from el-task-reorder into main 2026年05月12日 15:25:19 +02:00

Previously, reordering tasks was a pain. You had to remove and re-add task to
shift occurrence. This commit makes it much easier by using drag and drop.

The web drag and drop APIs are complex, especially if you want anything fancy.
I'm not trying to cover everything here.

Particularly tricky parts are there are a lot of events to keep track of and
depending on the event, the currentTarget might be the item you're dragging,
or item being "dragged over". There's also a gotcha that to make an element
droppable, you must call event.preventDefault() when it's being dragged over.

Overall, it's worth studying up on how all if it works before diving in too
deep.

I cribbed a lot of info from an onrails.blog tutorial:
https://onrails.blog/2018/03/09/stimulus-js-tutorial-how-do-i-drag-and-drop-items-in-a-list/

Also very useful was the MDN docs on the Drag and Drop API:
https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API

Previously, reordering tasks was a pain. You had to remove and re-add task to shift occurrence. This commit makes it much easier by using drag and drop. The web drag and drop APIs are _complex_, especially if you want anything fancy. I'm not trying to cover everything here. Particularly tricky parts are there are a lot of events to keep track of and depending on the event, the `currentTarget` might be the item you're dragging, or item being "dragged over". There's also a gotcha that to make an element droppable, you must call `event.preventDefault()` when it's being dragged over. Overall, it's worth studying up on how all if it works before diving in too deep. I cribbed a lot of info from an onrails.blog tutorial: https://onrails.blog/2018/03/09/stimulus-js-tutorial-how-do-i-drag-and-drop-items-in-a-list/ Also very useful was the MDN docs on the Drag and Drop API: https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API <video src="/attachments/5ed2ae17-8fdc-43b5-97d8-fa530f76eb4e" width="1035" height="745" controls></video>
Drag and drop to reorder tasks
Some checks failed
ci/woodpecker/pr/ci Pipeline failed
a61dac5926
Previously, reordering tasks was a pain. You had to remove and re-add task to
shift occurrence. This commit makes it much easier by using drag and drop.
The web drag and drop APIs are _complex_, especially if you want anything fancy.
I'm not trying to cover everything here.
Particularly tricky parts are there are a lot of events to keep track of and
depending on the event, the `currentTarget` might be the item you're dragging,
or item being "dragged over". There's also a gotcha that to make an element
droppable, you must call `event.preventDefault()` when it's being dragged over.
Overall, it's worth studying up on how all if it works before diving in too
deep.
I cribbed a lot of info from an onrails.blog tutorial:
https://onrails.blog/2018/03/09/stimulus-js-tutorial-how-do-i-drag-and-drop-items-in-a-list/
Also very useful was the MDN docs on the Drag and Drop API:
https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API 
edwardloveall force-pushed el-task-reorder from a61dac5926
Some checks failed
ci/woodpecker/pr/ci Pipeline failed
to f1ab6c4e0c
All checks were successful
ci/woodpecker/pr/ci Pipeline was successful
2026年05月07日 22:09:14 +02:00
Compare
edwardloveall force-pushed el-task-reorder from f1ab6c4e0c
All checks were successful
ci/woodpecker/pr/ci Pipeline was successful
to 6e0cb45c3c
Some checks failed
ci/woodpecker/pr/ci Pipeline failed
2026年05月07日 22:34:16 +02:00
Compare
edwardloveall force-pushed el-task-reorder from 6e0cb45c3c
Some checks failed
ci/woodpecker/pr/ci Pipeline failed
to e009134b11
All checks were successful
ci/woodpecker/pr/ci Pipeline was successful
2026年05月11日 17:18:49 +02:00
Compare
edwardloveall force-pushed el-task-reorder from e009134b11
All checks were successful
ci/woodpecker/pr/ci Pipeline was successful
to 4487686f40
Some checks failed
ci/woodpecker/pr/ci Pipeline failed
2026年05月11日 22:54:40 +02:00
Compare
thetizzo left a comment
Copy link

This looks good, implementation seems pretty clean. Given your comments on the complexity here though, I would be curious if there is a small open source library that would encapsulate drag and drop integration well, just so you wouldn't have to worry about maintaining it over time. Maybe that is just trading one kind of maintenance for another? Can always add this later if it becomes a burden too. Just food for thought.

This looks good, implementation seems pretty clean. Given your comments on the complexity here though, I would be curious if there is a small open source library that would encapsulate drag and drop integration well, just so you wouldn't have to worry about maintaining it over time. Maybe that is just trading one kind of maintenance for another? Can always add this later if it becomes a burden too. Just food for thought.
edwardloveall changed target branch from el-stimulus to main 2026年05月12日 15:09:58 +02:00
Author
Owner
Copy link

I would be curious if there is a small open source library that would encapsulate drag and drop integration well

I wondered the same thing. I do like deeply understanding what's happening under the hood, but there's obviously a limit. I also don't want to fall completely into the "not invented here" trap. I think if this ends up churning a lot it would be worth grabbing a library.

> I would be curious if there is a small open source library that would encapsulate drag and drop integration well I wondered the same thing. I do like deeply understanding what's happening under the hood, but there's obviously a limit. I also don't want to fall completely into the "not invented here" trap. I think if this ends up churning a lot it would be worth grabbing a library.
Author
Owner
Copy link

This test is being the bane of my existence. It passes locally most of the time and fails on CI (of course). I'll probably try to re-work it so it's testing less at a time, or make a no-js version which may help.

This test is being the bane of my existence. It passes locally most of the time and fails on CI (of course). I'll probably try to re-work it so it's testing less at a time, or make a no-js version which may help.
edwardloveall deleted branch el-task-reorder 2026年05月12日 15:25:19 +02:00
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
rootable/tomato!155
Reference in a new issue
rootable/tomato
No description provided.
Delete branch "el-task-reorder"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?