Skip to content

Commit 232fb3e

Browse files
feat: add initial resignation confirmation modal
1 parent c062cf6 commit 232fb3e

File tree

4 files changed

+88
-2
lines changed

4 files changed

+88
-2
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
interface ResignationConfirmModalProps {
2+
isOpen: boolean
3+
onClose: () => void
4+
onConfirm: () => void
5+
}
6+
7+
export const ResignationConfirmModal: React.FC<
8+
ResignationConfirmModalProps
9+
> = ({ isOpen, onClose, onConfirm }) => {
10+
if (!isOpen) return null
11+
12+
const handleConfirm = () => {
13+
onConfirm()
14+
onClose()
15+
}
16+
17+
return (
18+
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50">
19+
<div className="w-full max-w-sm rounded-lg bg-background-1 p-6 shadow-lg">
20+
<h3 className="mb-4 text-lg font-semibold text-primary">
21+
Confirm Resignation
22+
</h3>
23+
24+
<p className="mb-6 text-sm text-secondary">
25+
Are you sure you want to resign this game? This action cannot be
26+
undone.
27+
</p>
28+
29+
<div className="flex gap-3">
30+
<button
31+
onClick={onClose}
32+
className="flex-1 rounded border border-white border-opacity-20 px-4 py-2 text-sm text-secondary transition hover:bg-background-2"
33+
>
34+
Cancel
35+
</button>
36+
<button
37+
onClick={handleConfirm}
38+
className="flex-1 rounded bg-red-600 px-4 py-2 text-sm text-white transition hover:bg-red-700"
39+
>
40+
Resign
41+
</button>
42+
</div>
43+
</div>
44+
</div>
45+
)
46+
}

src/components/Common/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ export * from './ModalContainer'
1717
export * from './ContinueAgainstMaia'
1818
export * from './AnimatedNumber'
1919
export * from './DownloadModelModal'
20+
export * from './ResignationConfirmModal'

src/components/Play/HandBrainPlayControls.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/* eslint-disable @next/next/no-img-element */
22
/* eslint-disable jsx-a11y/alt-text */
3+
import { useState } from 'react'
34
import { PieceSymbol } from 'chess.ts'
45

56
import { BaseGame, Color } from 'src/types'
7+
import { ResignationConfirmModal } from 'src/components'
68

79
const pieceTypes: PieceSymbol[] = ['k', 'q', 'r', 'b', 'n', 'p']
810

@@ -52,6 +54,17 @@ export const HandBrainPlayControls: React.FC<Props> = ({
5254
simulateMaiaTime,
5355
setSimulateMaiaTime,
5456
}: Props) => {
57+
const [showResignConfirm, setShowResignConfirm] = useState(false)
58+
59+
const handleResignClick = () => {
60+
setShowResignConfirm(true)
61+
}
62+
63+
const handleConfirmResign = () => {
64+
if (resign) {
65+
resign()
66+
}
67+
}
5568
const status = playerActive
5669
? isBrain
5770
? selectedPiece
@@ -218,7 +231,7 @@ export const HandBrainPlayControls: React.FC<Props> = ({
218231
{/* Resign Button - Smaller and Less Prominent */}
219232
<div className="flex justify-center">
220233
<button
221-
onClick={resign}
234+
onClick={handleResignClick}
222235
disabled={!resign || !playerActive}
223236
className={`rounded px-3 py-1 text-xs font-medium transition-colors duration-200 ${
224237
resign && playerActive
@@ -234,6 +247,12 @@ export const HandBrainPlayControls: React.FC<Props> = ({
234247
</>
235248
)}
236249
</div>
250+
251+
<ResignationConfirmModal
252+
isOpen={showResignConfirm}
253+
onClose={() => setShowResignConfirm(false)}
254+
onConfirm={handleConfirmResign}
255+
/>
237256
</div>
238257
)
239258
}

src/components/Play/PlayControls.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import { useState } from 'react'
2+
13
import { BaseGame } from 'src/types'
4+
import { ResignationConfirmModal } from 'src/components'
25

36
interface Props {
47
game: BaseGame
@@ -21,6 +24,17 @@ export const PlayControls: React.FC<Props> = ({
2124
simulateMaiaTime,
2225
setSimulateMaiaTime,
2326
}: Props) => {
27+
const [showResignConfirm, setShowResignConfirm] = useState(false)
28+
29+
const handleResignClick = () => {
30+
setShowResignConfirm(true)
31+
}
32+
33+
const handleConfirmResign = () => {
34+
if (resign) {
35+
resign()
36+
}
37+
}
2438
return (
2539
<div className="flex h-full w-full flex-col border-white/40 bg-background-1">
2640
{gameOver ? (
@@ -112,7 +126,7 @@ export const PlayControls: React.FC<Props> = ({
112126
{/* Resign Button - Smaller and Less Prominent */}
113127
<div className="flex justify-center">
114128
<button
115-
onClick={resign}
129+
onClick={handleResignClick}
116130
disabled={!resign || !playerActive}
117131
className={`rounded px-3 py-1 text-xs font-medium transition-colors duration-200 ${
118132
resign && playerActive
@@ -127,6 +141,12 @@ export const PlayControls: React.FC<Props> = ({
127141
</div>
128142
</>
129143
)}
144+
145+
<ResignationConfirmModal
146+
isOpen={showResignConfirm}
147+
onClose={() => setShowResignConfirm(false)}
148+
onConfirm={handleConfirmResign}
149+
/>
130150
</div>
131151
)
132152
}

0 commit comments

Comments
 (0)