Skip to content

Commit

Permalink
Allow for HighlightNeighbors on Mobile
Browse files Browse the repository at this point in the history
This isn't a perfect implementation, but it does allow for tap+hold to
highlight neighbors on mobile.

Shortcomings:
- When releasing a "long press", neighbors will not be revealed, as is
  the case on desktop. So, have to release the long press and then do
  another short press / tap to do the Reveal Neighbors action.
  • Loading branch information
pdobb committed Mar 9, 2025
1 parent 3613971 commit 3b514a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/javascript/controllers/games/current/board/cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class Cell {
}

dehighlightNeighbors(url) {
if (this.isNotRevealed || this.isBlank) return

this.#submit(url)
}

Expand Down
7 changes: 6 additions & 1 deletion app/javascript/controllers/games/current/board_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export default class extends Controller {
if (this.isDesktop) return
this.longPressExecuted = this.touchMoveDetected = false

cell(event.target).highlightNeighbors(this.highlightNeighborsUrlValue)

this.longPressTimer = touch(event).onLongPress(() => {
this.longPressExecuted = true
this.#longPress(event)
Expand All @@ -104,7 +106,10 @@ export default class extends Controller {

dispatchTouchEnd(event) {
if (this.isDesktop) return
if (this.touchMoveDetected || this.longPressExecuted) return
if (this.touchMoveDetected || this.longPressExecuted) {
cell(event.target).dehighlightNeighbors(this.dehighlightNeighborsUrlValue)
return
}

clearTimeout(this.longPressTimer)
this.#tap(event)
Expand Down

0 comments on commit 3b514a8

Please sign in to comment.