Skip to content

Commit 5a5a3dc

Browse files
committed
feat(dave): Add UI for eliminated matches on Tournament view.
1 parent 59fb6b6 commit 5a5a3dc

2 files changed

Lines changed: 108 additions & 15 deletions

File tree

apps/dave/src/components/tournament/MatchCard.stories.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ export const Winner2: Story = {
101101
},
102102
};
103103

104+
export const MatchEliminated: Story = {
105+
args: {
106+
match: {
107+
...match,
108+
winnerCommitment: "NONE",
109+
deletionReason: "TIMEOUT",
110+
},
111+
},
112+
};
113+
104114
/**
105115
* A match without a onClick event handler, which should change the cursor feedback.
106116
*/

apps/dave/src/components/tournament/MatchCard.tsx

Lines changed: 98 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import type { Match } from "@cartesi/viem";
22
import {
3+
Button,
34
Card,
45
Group,
56
Overlay,
67
Stack,
78
Text,
9+
Tooltip,
810
useMantineTheme,
911
type CardProps,
1012
} from "@mantine/core";
13+
import { useDisclosure } from "@mantine/hooks";
1114
import type { FC } from "react";
12-
import { TbTrophyFilled } from "react-icons/tb";
15+
import { TbInfoCircle, TbTrophyFilled } from "react-icons/tb";
1316
import { ClaimText } from "../ClaimText";
1417

1518
export interface MatchCardProps extends CardProps {
@@ -24,11 +27,66 @@ export interface MatchCardProps extends CardProps {
2427
onClick?: () => void;
2528
}
2629

27-
export const MatchCard: FC<MatchCardProps> = ({
28-
match,
29-
onClick,
30-
...cardProps
31-
}) => {
30+
const wording = {
31+
matchEliminated:
32+
"Match was eliminated due to both commitments failure to act on time.",
33+
} as const;
34+
35+
const MatchEliminated: FC<MatchCardProps> = ({ match }) => {
36+
const [opened, handlers] = useDisclosure(false);
37+
const claim1 = { hash: match.commitmentOne };
38+
const claim2 = { hash: match.commitmentTwo };
39+
40+
return (
41+
<>
42+
<Group gap={0} align="stretch" pe="md">
43+
<Tooltip
44+
label={
45+
<Text fw="bold" size="sm">
46+
{wording["matchEliminated"]}
47+
</Text>
48+
}
49+
opened={opened}
50+
multiline
51+
withArrow
52+
arrowSize={8}
53+
>
54+
<Button
55+
component="div"
56+
px="5"
57+
h="auto"
58+
variant="light"
59+
onClick={(evt) => {
60+
evt.stopPropagation();
61+
handlers.toggle();
62+
}}
63+
>
64+
<TbInfoCircle size={24} />
65+
</Button>
66+
</Tooltip>
67+
<Stack gap={0} py="md" pl="sm">
68+
<Group gap="xs" wrap="nowrap">
69+
<ClaimText
70+
claim={claim1}
71+
td="line-through"
72+
copyButton={false}
73+
/>
74+
</Group>
75+
<Text style={{ textAlign: "center" }}>vs</Text>
76+
<Group gap="xs" wrap="nowrap">
77+
<ClaimText
78+
claim={claim2}
79+
td="line-through"
80+
copyButton={false}
81+
/>
82+
</Group>
83+
</Stack>
84+
</Group>
85+
</>
86+
);
87+
};
88+
89+
const Match: FC<MatchCardProps> = ({ match }) => {
3290
const claim1 = { hash: match.commitmentOne };
3391
const claim2 = { hash: match.commitmentTwo };
3492
const winner = match.winnerCommitment;
@@ -37,15 +95,7 @@ export const MatchCard: FC<MatchCardProps> = ({
3795
const showWinner = winner !== "NONE";
3896

3997
return (
40-
<Card
41-
component="button"
42-
withBorder
43-
shadow="sm"
44-
radius="lg"
45-
{...cardProps}
46-
onClick={onClick}
47-
style={{ cursor: onClick ? "pointer" : undefined }}
48-
>
98+
<>
4999
<Overlay
50100
bg={gold}
51101
opacity={showWinner && winner === "ONE" ? 0.1 : 0}
@@ -100,6 +150,39 @@ export const MatchCard: FC<MatchCardProps> = ({
100150
/>
101151
</Group>
102152
</Stack>
153+
</>
154+
);
155+
};
156+
157+
export const MatchCard: FC<MatchCardProps> = ({
158+
match,
159+
onClick,
160+
...cardProps
161+
}) => {
162+
const isMatchEliminated =
163+
match.deletionReason === "TIMEOUT" && match.winnerCommitment === "NONE";
164+
const cardPadding = isMatchEliminated ? "0" : "";
165+
166+
return (
167+
<Card
168+
component="button"
169+
withBorder
170+
shadow="sm"
171+
radius="lg"
172+
{...cardProps}
173+
onClick={onClick}
174+
style={{ cursor: onClick ? "pointer" : undefined }}
175+
p={cardPadding}
176+
>
177+
{isMatchEliminated ? (
178+
<MatchEliminated
179+
match={match}
180+
onClick={onClick}
181+
{...cardProps}
182+
/>
183+
) : (
184+
<Match match={match} />
185+
)}
103186
</Card>
104187
);
105188
};

0 commit comments

Comments
 (0)