Skip to content

Commit

Permalink
Support double clicking to move draggable
Browse files Browse the repository at this point in the history
  • Loading branch information
ApsiV11 committed Dec 7, 2024
1 parent a8f7c8c commit 3d77183
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/frontend/components/vote/Vote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ export const Vote = () => {
setDisableVote(false)
}

const handleDoubleClickAdd = (event: React.MouseEvent<HTMLElement>) => {
const candidateId = event.currentTarget.id
setSelectedCandidates((prev) => [...prev, candidateId])
setAvailableCandidates((prev) => prev.filter((c) => c !== candidateId))
}

const handleDoubleClickRemove = (event: React.MouseEvent<HTMLElement>) => {
const candidateId = event.currentTarget.id
setAvailableCandidates((prev) => [...prev, candidateId])
setSelectedCandidates((prev) => prev.filter((c) => c !== candidateId))
}

useEffect(() => {
void (async () => {
if (!voterId) {
Expand Down Expand Up @@ -239,9 +251,11 @@ export const Vote = () => {
{(provided) => (
<ListGroup.Item
ref={provided.innerRef}
id={candidateId}
{...provided.draggableProps}
{...provided.dragHandleProps}
className="d-flex align-items-center mb-2"
onDoubleClick={handleDoubleClickRemove}
>
{index + 1}. &nbsp;{' '}
{getCandidateName(candidateId)}
Expand Down Expand Up @@ -279,9 +293,11 @@ export const Vote = () => {
{(provided) => (
<ListGroup.Item
ref={provided.innerRef}
id={candidateId}
{...provided.draggableProps}
{...provided.dragHandleProps}
className="d-flex align-items-center mb-2"
onDoubleClick={handleDoubleClickAdd}
>
{getCandidateName(candidateId)}
</ListGroup.Item>
Expand Down

0 comments on commit 3d77183

Please sign in to comment.