fix: meals drag & drop crash — destructure dragging before cleanup()
cleanup() set dragging = null, then onUp accessed dragging.slot, .mealId, .sourceDate, .sourceType on the now-null reference. Fix: destructure all needed values before calling cleanup(). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -349,20 +349,21 @@ function wireDragDrop(grid) {
|
||||
|
||||
async function onUp(ev) {
|
||||
if (!dragging) return;
|
||||
cleanup();
|
||||
const { mealId, sourceDate, sourceType, slot: sourceSlot } = dragging;
|
||||
cleanup(); // setzt dragging = null — Werte daher vorher destrukturieren
|
||||
|
||||
if (ghost) ghost.style.display = 'none';
|
||||
const el = document.elementFromPoint(ev.clientX, ev.clientY);
|
||||
if (ghost) ghost.style.display = '';
|
||||
|
||||
const targetSlot = el?.closest('.meal-slot');
|
||||
if (targetSlot && targetSlot !== dragging.slot) {
|
||||
if (targetSlot && targetSlot !== sourceSlot) {
|
||||
const targetDate = targetSlot.dataset.date;
|
||||
const targetType = targetSlot.dataset.type;
|
||||
const targetMealId = targetSlot.dataset.mealId ? parseInt(targetSlot.dataset.mealId, 10) : null;
|
||||
_suppressNextClick = true;
|
||||
setTimeout(() => { _suppressNextClick = false; }, 300);
|
||||
await moveMeal(dragging.mealId, dragging.sourceDate, dragging.sourceType, targetDate, targetType, targetMealId);
|
||||
await moveMeal(mealId, sourceDate, sourceType, targetDate, targetType, targetMealId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user