mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-14 22:01:09 +02:00
fix(todo): improve drag-and-drop reliability with ID-based sync
Use sorted task IDs instead of array reference to detect real changes from parent. Update lastTaskIds after finalize to prevent $effect from reverting local DnD state changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
aeb6a15994
commit
75bf7ecf47
1 changed files with 15 additions and 6 deletions
|
|
@ -25,14 +25,18 @@
|
|||
// Local mutable state for dnd-zone
|
||||
let items = $state<Task[]>([]);
|
||||
|
||||
// Track last known tasks reference to detect parent updates
|
||||
let lastTasksRef: Task[] | null = null;
|
||||
// Create a stable key from task IDs to detect real changes
|
||||
let lastTaskIds = '';
|
||||
|
||||
// Sync items with tasks only when tasks array reference changes
|
||||
$effect.pre(() => {
|
||||
if (tasks !== lastTasksRef) {
|
||||
// Sync items with tasks only when the set of task IDs changes
|
||||
$effect(() => {
|
||||
const currentIds = tasks
|
||||
.map((t) => t.id)
|
||||
.sort()
|
||||
.join(',');
|
||||
if (currentIds !== lastTaskIds) {
|
||||
items = [...tasks];
|
||||
lastTasksRef = tasks;
|
||||
lastTaskIds = currentIds;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -54,7 +58,12 @@
|
|||
onTaskDrop(movedTaskId, dropTargetDate);
|
||||
}
|
||||
|
||||
// Update local state and sync lastTaskIds to prevent $effect from reverting
|
||||
items = newItems;
|
||||
lastTaskIds = newItems
|
||||
.map((t) => t.id)
|
||||
.sort()
|
||||
.join(',');
|
||||
}
|
||||
|
||||
async function handleToggleComplete(task: Task) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue