Simplify drop indicator logic.
This commit is contained in:
parent
e8064b0aff
commit
2e6cd66f56
2 changed files with 18 additions and 22 deletions
2
TODO.md
2
TODO.md
|
|
@ -15,7 +15,6 @@
|
||||||
|
|
||||||
## Refactor
|
## Refactor
|
||||||
|
|
||||||
- [ ] Simplify drop indicator logic
|
|
||||||
- [ ] Consolidate menu creation (card menus and burger menu)
|
- [ ] Consolidate menu creation (card menus and burger menu)
|
||||||
- [ ] Extract line parsing logic - separate parsing from state management
|
- [ ] Extract line parsing logic - separate parsing from state management
|
||||||
- [ ] Reduce IndexedDB boilerplate with generic DB operation wrapper
|
- [ ] Reduce IndexedDB boilerplate with generic DB operation wrapper
|
||||||
|
|
@ -24,6 +23,7 @@
|
||||||
|
|
||||||
## Done
|
## Done
|
||||||
|
|
||||||
|
- [x] Simplify drop indicator logic
|
||||||
- [x] Extract file operations into higher-level abstraction
|
- [x] Extract file operations into higher-level abstraction
|
||||||
- [x] Consolidate modal logic into generic modal handler
|
- [x] Consolidate modal logic into generic modal handler
|
||||||
- [x] Warning colored note on home and about page if browser doesn't support FileSystem Access API.
|
- [x] Warning colored note on home and about page if browser doesn't support FileSystem Access API.
|
||||||
|
|
|
||||||
38
index.html
38
index.html
|
|
@ -956,8 +956,7 @@ chmod 755 kbtd
|
||||||
};
|
};
|
||||||
|
|
||||||
let dragState = {
|
let dragState = {
|
||||||
source: null,
|
source: null
|
||||||
currentDropTarget: null
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let moveModalState = {
|
let moveModalState = {
|
||||||
|
|
@ -2130,18 +2129,22 @@ chmod 755 kbtd
|
||||||
renderBoard();
|
renderBoard();
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearDropIndicators() {
|
|
||||||
$$('.drop-indicator').forEach(el => el.classList.remove('active'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function setActiveDropIndicator(colIndex, position) {
|
function setActiveDropIndicator(colIndex, position) {
|
||||||
console.log('Setting active drop indicator: col', colIndex, 'position', position);
|
console.log('Setting active drop indicator: col', colIndex, 'position', position);
|
||||||
dragState.currentDropTarget = { colIndex, position };
|
$$('.drop-indicator').forEach(el => el.classList.remove('active'));
|
||||||
clearDropIndicators();
|
|
||||||
const indicator = $(`.drop-indicator[data-col-index="${colIndex}"][data-position="${position}"]`);
|
const indicator = $(`.drop-indicator[data-col-index="${colIndex}"][data-position="${position}"]`);
|
||||||
if (indicator) indicator.classList.add('active');
|
if (indicator) indicator.classList.add('active');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getActiveDropIndicator() {
|
||||||
|
const active = $('.drop-indicator.active');
|
||||||
|
if (!active) return null;
|
||||||
|
return {
|
||||||
|
colIndex: getDataInt(active, 'colIndex'),
|
||||||
|
position: getDataInt(active, 'position')
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function handleDragStart(e, cardDiv) {
|
function handleDragStart(e, cardDiv) {
|
||||||
closeAllCardMenus();
|
closeAllCardMenus();
|
||||||
dragState.source = {
|
dragState.source = {
|
||||||
|
|
@ -2157,9 +2160,8 @@ chmod 755 kbtd
|
||||||
|
|
||||||
function handleDragEnd(e) {
|
function handleDragEnd(e) {
|
||||||
e.target.classList.remove('dragging');
|
e.target.classList.remove('dragging');
|
||||||
clearDropIndicators();
|
$$('.drop-indicator').forEach(el => el.classList.remove('active'));
|
||||||
dragState.source = null;
|
dragState.source = null;
|
||||||
dragState.currentDropTarget = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleCardDragEnter(e, cardDiv, colIndex, cardIndex) {
|
function handleCardDragEnter(e, cardDiv, colIndex, cardIndex) {
|
||||||
|
|
@ -2208,12 +2210,7 @@ chmod 755 kbtd
|
||||||
if (closestCard) {
|
if (closestCard) {
|
||||||
const cardIndex = getDataInt(closestCard, 'cardIndex');
|
const cardIndex = getDataInt(closestCard, 'cardIndex');
|
||||||
const position = insertBefore ? cardIndex : cardIndex + 1;
|
const position = insertBefore ? cardIndex : cardIndex + 1;
|
||||||
|
setActiveDropIndicator(colIndex, position);
|
||||||
if (!dragState.currentDropTarget ||
|
|
||||||
dragState.currentDropTarget.colIndex !== colIndex ||
|
|
||||||
dragState.currentDropTarget.position !== position) {
|
|
||||||
setActiveDropIndicator(colIndex, position);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2230,16 +2227,17 @@ chmod 755 kbtd
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
clearDropIndicators();
|
const dropTarget = getActiveDropIndicator();
|
||||||
|
$$('.drop-indicator').forEach(el => el.classList.remove('active'));
|
||||||
|
|
||||||
if (!dragState.source || !dragState.currentDropTarget) {
|
if (!dragState.source || !dropTarget) {
|
||||||
console.log('Drop ignored: no source or target');
|
console.log('Drop ignored: no source or target');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sourceColIndex = dragState.source.colIndex;
|
const sourceColIndex = dragState.source.colIndex;
|
||||||
const sourceLineNumber = dragState.source.lineNumber;
|
const sourceLineNumber = dragState.source.lineNumber;
|
||||||
const targetPosition = dragState.currentDropTarget.position;
|
const targetPosition = dropTarget.position;
|
||||||
|
|
||||||
console.log('Drop: sourceCol', sourceColIndex, 'targetCol', targetColIndex, 'position', targetPosition);
|
console.log('Drop: sourceCol', sourceColIndex, 'targetCol', targetColIndex, 'position', targetPosition);
|
||||||
|
|
||||||
|
|
@ -2248,7 +2246,6 @@ chmod 755 kbtd
|
||||||
if (targetPosition === sourceCardIndex || targetPosition === sourceCardIndex + 1) {
|
if (targetPosition === sourceCardIndex || targetPosition === sourceCardIndex + 1) {
|
||||||
console.log('Same position, ignoring drop');
|
console.log('Same position, ignoring drop');
|
||||||
dragState.source = null;
|
dragState.source = null;
|
||||||
dragState.currentDropTarget = null;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2261,7 +2258,6 @@ chmod 755 kbtd
|
||||||
await moveLineInFile(sourceLineNumber, 0, targetColIndex, targetPosition);
|
await moveLineInFile(sourceLineNumber, 0, targetColIndex, targetPosition);
|
||||||
|
|
||||||
dragState.source = null;
|
dragState.source = null;
|
||||||
dragState.currentDropTarget = null;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue