Skip to content

Commit 8dd734b

Browse files
committed
added rating color/circle
1 parent cf8f4ee commit 8dd734b

3 files changed

Lines changed: 88 additions & 35 deletions

File tree

package-lock.json

Lines changed: 2 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ListWidget.css

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@
8686
line-height: 1.3;
8787
}
8888

89+
.oi-list-item__header {
90+
display: flex;
91+
justify-content: space-between;
92+
align-items: center
93+
}
94+
8995
.oi-list-item__tags {
9096
display: flex;
9197
flex-wrap: wrap;
@@ -113,8 +119,32 @@
113119
transition: color 0.15s ease, transform 0.15s ease;
114120
}
115121

122+
.oi-list-rating-circle {
123+
width: 14px;
124+
height: 14px;
125+
border: 2px solid var(--color);
126+
border-radius: 50%;
127+
overflow: hidden;
128+
position: relative;
129+
flex-shrink: 0;
130+
}
131+
.oi-list-item__rating {
132+
display: flex;
133+
align-items: center;
134+
gap: 6px;
135+
}
136+
137+
.oi-list-rating-circle__fill {
138+
position: absolute;
139+
left: 0;
140+
right: 0;
141+
bottom: 0;
142+
height: var(--fill);
143+
background: var(--color);
144+
}
145+
116146
@media (max-width: 860px) {
117147
.oi-list-toolbar {
118148
grid-template-columns: 1fr;
119149
}
120-
}
150+
}

src/ListWidget.jsx

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,44 @@ const SORT_OPTIONS = [
1010
{ value: "name-asc", label: "Nazwa (A-Z)" },
1111
];
1212

13+
const RATING_COLORS = {
14+
800: "#919191",
15+
1600: "#5bcfa2",
16+
2600: "#6de2e8",
17+
3200: "#775cd1",
18+
4000: "#ffd56b",
19+
5000: "#fcae65",
20+
6000: "#ed9a93",
21+
8001: "#ffffff"
22+
};
23+
24+
function getRatingInfo(rating) {
25+
const thresholds = Object.keys(RATING_COLORS)
26+
.map(Number)
27+
.sort((a, b) => a - b);
28+
29+
let current = thresholds[0];
30+
let next = null;
31+
32+
for (let i = 0; i < thresholds.length; i++) {
33+
if (rating >= thresholds[i]) {
34+
current = thresholds[i];
35+
next = thresholds[i + 1] ?? null;
36+
} else {
37+
break;
38+
}
39+
}
40+
41+
const progress = next
42+
? (rating - current) / (next - current)
43+
: 1;
44+
45+
return {
46+
color: RATING_COLORS[current],
47+
progress: Math.max(0, Math.min(progress, 1)),
48+
};
49+
}
50+
1351
const getText = (value) => {
1452
if (typeof value === "string") {
1553
return value;
@@ -192,14 +230,29 @@ const ListWidget = ({ dataUrl = DEFAULT_RESULTS_URL, embedded = false }) => {
192230
{!loading && !error ? (
193231
<div className="oi-list-results">
194232
{visibleProblems.map((problem) => {
233+
const { color, progress } = getRatingInfo(problem.rating);
234+
195235
const content = (
196236
<>
197-
<span className="oi-list-item__name">{problem.name}</span>
237+
<div className="oi-list-item__header">
238+
<span className="oi-list-item__name">{problem.name}</span>
239+
<div className="oi-list-item__rating">
240+
<span style={{ color: color }}>{problem.rating}</span>
241+
<div
242+
className="oi-list-rating-circle"
243+
style={{
244+
"--fill": `${progress * 100}%`,
245+
"--color": color,
246+
}}
247+
>
248+
<div className="oi-list-rating-circle__fill" />
249+
</div>
250+
</div>
251+
</div>
198252
<span className="oi-list-item__tags">
199253
<code>{problem.code || "N/A"}</code>
200254
<span>etap {problem.stage || "?"}</span>
201255
<span>edycja {problem.year || "?"}</span>
202-
<span>rating {problem.rating || 0}</span>
203256
</span>
204257
{problem.url ? (
205258
<svg

0 commit comments

Comments
 (0)