-
-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathProblemLink.tsx
More file actions
148 lines (139 loc) · 3.92 KB
/
ProblemLink.tsx
File metadata and controls
148 lines (139 loc) · 3.92 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import React, { useState } from "react";
import { Tooltip } from "reactstrap";
import * as Url from "../utils/Url";
import { getRatingColorClass } from "../utils";
import ProblemModel from "../interfaces/ProblemModel";
import { RatingInfo } from "../utils/RatingInfo";
import { ShowDifficultyMode } from "../utils/ShowDifficultyMode";
import { DifficultyCircle } from "./DifficultyCircle";
import { NewTabLink } from "./NewTabLink";
interface Props {
className?: string;
problemId: string;
contestId: string;
problemIndex?: string;
problemName: string;
showDifficultyMode: ShowDifficultyMode;
isExperimentalDifficulty?: boolean;
showDifficultyUnavailable?: boolean;
problemModel?: ProblemModel | null;
userRatingInfo?: RatingInfo | null;
}
export const ProblemLink: React.FC<Props> = (props) => {
const [tooltipOpen, setTooltipOpen] = useState(false);
const [showDifficultySubClicked, setshowDifficultySubClicked] = useState(
false
);
const {
contestId,
problemId,
problemIndex,
problemName,
showDifficultyMode,
isExperimentalDifficulty,
showDifficultyUnavailable,
problemModel,
userRatingInfo,
} = props;
const problemTitle = problemIndex
? `${problemIndex}. ${problemName}`
: problemName;
const simpleLink = (
<NewTabLink
href={Url.formatProblemUrl(problemId, contestId)}
className={props.className}
>
{problemTitle}
</NewTabLink>
);
const difficulty = problemModel?.difficulty;
if (
problemModel === undefined ||
(difficulty === undefined && !showDifficultyUnavailable)
) {
return simpleLink;
}
const uniqueId = problemId + "-" + contestId;
const experimentalIconId = "experimental-" + uniqueId;
const showDifficultySubIconId = "show-difficulty-sub-" + uniqueId;
const ratingColorClass =
difficulty === undefined ? undefined : getRatingColorClass(difficulty);
const experimentalDifficultySymbol = (
<>
<span id={experimentalIconId} role="img" aria-label="experimental">
🧪
</span>
<Tooltip
placement="top"
target={experimentalIconId}
isOpen={tooltipOpen}
toggle={(): void => setTooltipOpen(!tooltipOpen)}
>
This estimate is experimental.
</Tooltip>
</>
);
const showDifficultySubSymbol = (
<>
<button
id={showDifficultySubIconId}
role="img"
aria-label="show-difficulty-sub"
onClick={(): void =>
setshowDifficultySubClicked(!showDifficultySubClicked)
}
style={{
border: "none",
background: "transparent",
}}
>
{"👉 "}
</button>
</>
);
const difficultyColoredLink = (
// Don't add rel="noreferrer" to AtCoder links
// to allow AtCoder get the referral information.
// eslint-disable-next-line react/jsx-no-target-blank
<a
href={Url.formatProblemUrl(problemId, contestId)}
// Don't add rel="noreferrer" to AtCoder links
// to allow AtCoder get the referral information.
// eslint-disable-next-line react/jsx-no-target-blank
target="_blank"
rel="noopener"
className={ratingColorClass}
>
{problemTitle}
</a>
);
const difficultySymbol = (
<>
<DifficultyCircle
id={uniqueId}
problemModel={problemModel}
userRatingInfo={userRatingInfo}
/>
{isExperimentalDifficulty ? experimentalDifficultySymbol : null}
</>
);
switch (showDifficultyMode) {
case ShowDifficultyMode.None:
return <>{simpleLink}</>;
case ShowDifficultyMode.Full:
return (
<>
{difficultySymbol}
{difficultyColoredLink}
</>
);
case ShowDifficultyMode.Sub:
return (
<>
{showDifficultySubSymbol}
{showDifficultySubClicked ? difficultySymbol : null}
{showDifficultySubClicked ? difficultyColoredLink : simpleLink}
</>
);
}
};