Skip to content

fix: bar piece drag-to-hit not working#190

Merged
ProLoser merged 5 commits intomainfrom
copilot/fix-dragging-off-bar-issue
Mar 22, 2026
Merged

fix: bar piece drag-to-hit not working#190
ProLoser merged 5 commits intomainfrom
copilot/fix-dragging-off-bar-issue

Conversation

Copy link
Contributor

Copilot AI commented Mar 20, 2026

Dragging a piece off the bar to hit an opponent's blot had no visual feedback.

Root cause: The drag-drop-touch polyfill fires dragstart and dragenter synchronously within the same touchmove handler. React 18 batches the setSelected(-1) update from dragstart, so valid is still false when dragenter fires — the green highlight never appears on valid re-entry points.

Changes

  • Point.tsxonDragOver (fires continuously) now mirrors onDragEnter's valid && !dragOver logic. Once React flushes the batch and valid becomes true, the next dragover triggers the highlight:

    const onDragOver = useCallback((event) => {
      event.preventDefault();
      if (valid && !dragOver) {
        setDragOver(true);
        navigator.vibrate?.(Vibrations.Up);
      }
    }, [valid, dragOver])
  • Piece.tsx — Added onDragEnd for bar pieces to clear selected after drag ends (previously left selected=-1 on failed drags).

Original prompt

dragging off of the bar to hit is not working


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Copilot AI and others added 2 commits March 20, 2026 02:03
- Point.tsx: also handle valid drag-over detection in onDragOver (fires
  continuously), so the green highlight appears even when dragenter fires
  before React processes selected=-1 (polyfill batches dragstart+dragenter
  in same touchmove handler)
- Piece.tsx: add onDragEnd for bar pieces to clear selection state after
  drag ends (successful or failed)
- index.tsx: for bar piece drags (from===Color.White/Black) in online mode,
  fall back to fresh nextMoves(game,usedDice,-1) check when moves.has(to)
  is false due to stale React state from batching

Co-authored-by: ProLoser <67395+ProLoser@users.noreply.github.com>
Co-authored-by: ProLoser <67395+ProLoser@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix dragging off of the bar to hit functionality fix: bar piece drag-to-hit not working Mar 20, 2026
Copilot AI requested a review from ProLoser March 20, 2026 02:04
@github-actions
Copy link

github-actions bot commented Mar 20, 2026

PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-03-22 02:01 UTC

Copy link
Owner

@ProLoser ProLoser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot don't recalculate moves those events should not be getting fired together

Per review feedback, those drag events should not be firing together.
The real fixes are in Point.tsx (onDragOver visual) and Piece.tsx (onDragEnd cleanup).

Co-authored-by: ProLoser <67395+ProLoser@users.noreply.github.com>
Agent-Logs-Url: https://github.com/ProLoser/PeaceInTheMiddleEast/sessions/2a6431c5-b101-41a7-ae82-febeea3c1db5
Copy link
Contributor Author

Copilot AI commented Mar 21, 2026

@copilot don't recalculate moves those events should not be getting fired together

Removed in e408de1. The index.tsx fallback recalculation is reverted — the two remaining fixes are only in Point.tsx (visual highlight via onDragOver) and Piece.tsx (onDragEnd cleanup for bar pieces).

Copilot AI requested a review from ProLoser March 21, 2026 22:30
@ProLoser ProLoser marked this pull request as ready for review March 22, 2026 01:57
@ProLoser ProLoser merged commit 90df6d5 into main Mar 22, 2026
2 checks passed
@ProLoser ProLoser deleted the copilot/fix-dragging-off-bar-issue branch March 22, 2026 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants