Skip to content

Commit

Permalink
Removed hover styles and fixed tap/drag bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ProLoser committed Oct 12, 2024
1 parent 1eabee5 commit 117225d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/Board/Board.css
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ order:
.point {
height: 50%;
&:hover::before {
border-top-color: var(--primary-hover) !important;
/* border-top-color: var(--primary-hover) !important; */
}
&::before {
left: 50%;
Expand Down Expand Up @@ -141,10 +141,10 @@ order:
}

&:nth-child(even):hover::before {
border-bottom-color: var(--primary-hover) !important;
/* border-bottom-color: var(--primary-hover) !important; */
}
&:nth-child(odd):hover::before {
border-bottom-color: var(--secondary-hover) !important;
/* border-bottom-color: var(--secondary-hover) !important; */
}
/* Stack Pieces */
.piece:nth-child(n+6) {
Expand Down Expand Up @@ -176,10 +176,10 @@ order:
.point {
width: 50%;
&:nth-child(even):hover::before {
border-left-color: var(--primary-hover) !important;
/* border-left-color: var(--primary-hover) !important; */
}
&:nth-child(odd):hover::before {
border-left-color: var(--secondary-hover) !important;
/* border-left-color: var(--secondary-hover) !important; */
}

&::before {
Expand Down Expand Up @@ -221,7 +221,7 @@ order:
right: 0;
}
&:hover::before {
border-right-color: var(--primary-hover) !important;
/* border-right-color: var(--primary-hover) !important; */
}
&:nth-child(even)::before {
border-right-color: var(--secondary);
Expand Down
22 changes: 19 additions & 3 deletions src/Board/Point.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, type DragEventHandler } from "react";
import { useCallback, useState, type DragEventHandler } from "react";
import Piece from './Piece'

type PointProps = {
Expand All @@ -10,6 +10,7 @@ type PointProps = {
}

export default function Point({ pieces, move, position, onSelect, selected }: PointProps) {
const [isDragging, setIsDragging] = useState(false);
const onDragOver: DragEventHandler = useCallback((event) => { event.preventDefault(); }, [])
const onDrop: DragEventHandler = useCallback((event) => {
event.preventDefault();
Expand All @@ -20,12 +21,27 @@ export default function Point({ pieces, move, position, onSelect, selected }: Po

const color = pieces > 0 ? 'white' : 'black';

const handleDragStart = () => {
setIsDragging(true);
};

const handleDragEnd = () => {
setIsDragging(false);
};

const onPointerUp = useCallback(() => {
if (isDragging) return;
if (pieces !== 0 || selected !== null)
onSelect(position)
}, [pieces, position, onSelect])
}, [pieces, position, onSelect, isDragging])

return <div className={`point ${selected === position ? 'selected' : ''}`} onPointerUp={onPointerUp} onDragOver={onDragOver} onDrop={onDrop}>
return <div className={`point ${selected === position ? 'selected' : ''}`}
onPointerUp={onPointerUp}
onDragOver={onDragOver}
onDrop={onDrop}
onDragStart={handleDragStart}
onDragEnd={handleDragEnd}
>
{Array.from({ length: Math.abs(pieces) }, (_, index) => <Piece key={index} color={color} position={position} onSelect={onSelect} />)}
</div>
}
4 changes: 0 additions & 4 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ dialog {
color: black;
cursor: pointer;

&:hover {
color: blue;
}

&+menu,
&+[role="menu"] {
display: none;
Expand Down

0 comments on commit 117225d

Please sign in to comment.