Skip to content

Commit

Permalink
feat: support competition ranklist
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamerblue committed Dec 16, 2023
1 parent 1e5ce8d commit 886b83e
Show file tree
Hide file tree
Showing 8 changed files with 351 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "onlinejudge3-fe",
"version": "3.5.6",
"version": "3.5.7",
"description": "",
"scripts": {
"dev": "gulp dev",
Expand Down
7 changes: 4 additions & 3 deletions src/@types/models.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,10 @@ interface IContestUser {
}

interface IRanklistProblemResultStat {
result: 'FB' | 'AC' | 'X' | '-' | '?';
attempted: number;
result: 'FB' | 'AC' | 'RJ' | '?' | null;
tries: number;
time: number;
score?: number;
}

interface IRanklistRow {
Expand All @@ -243,7 +244,7 @@ interface IRanklistRow {
oldRating?: number;
newRating?: number;
};
solved: number;
score: number;
time: number;
stats: IRanklistProblemResultStat[];
_self?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/common
32 changes: 21 additions & 11 deletions src/components/Ranklist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface Props extends RouteProps {
rating?: boolean;
allowGodView?: boolean;
godView?: boolean;
useScore?: boolean;
handleGodViewChange?: (god: boolean) => any;
}

Expand Down Expand Up @@ -134,7 +135,7 @@ class Ranklist extends React.Component<Props, State> {
'Rank',
'Username',
'Nickname',
'Solved',
'Score',
'Time',
...problemIndex.map((pIndex) => numberToAlphabet(pIndex)),
],
Expand All @@ -144,14 +145,14 @@ class Ranklist extends React.Component<Props, State> {
d.rank,
d.user?.username || '',
d.user?.nickname || '',
d.solved,
d.score,
Math.floor(d.time / 60),
];
problemIndex.map((pIndex) => {
const stat = d.stats[pIndex];
let statText = '';
if (stat.attempted) {
statText = `${stat.attempted}`;
if (stat.tries) {
statText = `${stat.tries}`;
}
if (stat.result === 'AC' || stat.result === 'FB') {
statText += `/${Math.floor(stat.time / 60)}`;
Expand Down Expand Up @@ -182,6 +183,7 @@ class Ranklist extends React.Component<Props, State> {
location: { query },
rating,
allowGodView,
useScore,
} = this.props;
const { contentWidth, showAll } = this.state;
// const contentWidth = 0;
Expand Down Expand Up @@ -306,8 +308,8 @@ class Ranklist extends React.Component<Props, State> {
)}

<Table.Column
title="Slv."
key="Solved"
title="Score"
key="Score"
align="right"
width={width.solved}
fixed={canFixLeft}
Expand All @@ -319,7 +321,7 @@ class Ranklist extends React.Component<Props, State> {
query: { userId: record.user && record.user.userId },
})}
>
{record.solved}
{record.score}
</Link>
</div>
)}
Expand All @@ -342,21 +344,26 @@ class Ranklist extends React.Component<Props, State> {
render={(text, record: IRanklistRow) => {
const stat = record.stats[index];
let statText = '';
let extraText = '';
const classList: string[] = [];
if (stat.attempted) {
statText = `${stat.attempted}`;
if (stat.tries) {
statText = `${stat.tries}`;
}
if (stat.result === 'AC' || stat.result === 'FB') {
statText += `/${Math.floor(stat.time / 60)}`;
}
if (useScore && typeof stat.score === 'number') {
extraText = statText;
statText = `${stat.score}`;
}
switch (stat.result) {
case 'AC':
classList.push('accepted');
break;
case 'FB':
classList.push('fb');
break;
case 'X':
case 'RJ':
classList.push('failed');
break;
case '?':
Expand All @@ -365,7 +372,10 @@ class Ranklist extends React.Component<Props, State> {
}
return (
<div className={classNames('stat-inner', classList)}>
<span>{statText}</span>
<div>
<p>{statText}</p>
{!!extraText && <p className="stat-inner-extra">{extraText}</p>}
</div>
</div>
);
}}
Expand Down
9 changes: 8 additions & 1 deletion src/global.less
Original file line number Diff line number Diff line change
Expand Up @@ -981,10 +981,17 @@ ul {
width: 100%;
display: inline-table;

span {
div {
display: table-cell;
vertical-align: middle;
padding: 8px;
p {
margin-bottom: 0;
}
.stat-inner-extra {
font-size: 75%;
opacity: 0.65;
}
}
}
}
Expand Down
Loading

0 comments on commit 886b83e

Please sign in to comment.