-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpponentUserButton.tsx
More file actions
60 lines (51 loc) · 1.89 KB
/
OpponentUserButton.tsx
File metadata and controls
60 lines (51 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/** @jsxImportSource @emotion/react */
import ProfilePicture from "components/shared/ProfilePicture";
import React from "react";
import { IoIosGlobe } from "react-icons/io";
import { useNavigate } from "react-router-dom";
import { PlayerApi, RegisteredPlayerApi } from "types/api/player";
import { CSS } from "./css";
type Props = {
opponent: PlayerApi;
setIsOpponentButtonHovered: React.Dispatch<React.SetStateAction<boolean>>;
};
export default function OpponentUserButton(props: Props) {
const { opponent, setIsOpponentButtonHovered } = props;
const navigate = useNavigate();
const handleOpponentOnClick = (event: React.MouseEvent) => {
if (!isOpponentRegistered) return;
event.stopPropagation();
navigate(`/profile/${opponent.username}`);
};
const isOpponentRegistered = opponent.user_type !== "anonymous";
const OpponentDisplay = isOpponentRegistered
? getRegisteredOpponentDisplay(opponent)
: getAnonymousOpponentDisplay();
return (
<td
css={isOpponentRegistered && CSS.OPPONENT_PROFILE_BUTTON}
onClick={handleOpponentOnClick}
onMouseEnter={() => isOpponentRegistered && setIsOpponentButtonHovered(true)}
onMouseLeave={() => isOpponentRegistered && setIsOpponentButtonHovered(false)}
data-testid={`opponent-user-button`}
>
{OpponentDisplay}
</td>
);
}
const getRegisteredOpponentDisplay = (opponent: RegisteredPlayerApi) => {
return (
<div css={CSS.OPPONENT_USER_WRAPPER}>
<ProfilePicture username={opponent.username} customCss={CSS.PROFILE_PICTURE_ICON} />
{opponent.username}
</div>
);
};
const getAnonymousOpponentDisplay = () => {
return (
<div css={CSS.OPPONENT_USER_WRAPPER}>
<IoIosGlobe css={CSS.ANONYMOUS_USER_ICON} />
Anonymous
</div>
);
};