Skip to content

Commit

Permalink
順位表の時間表示を一部修正  (#182)
Browse files Browse the repository at this point in the history
* 最終AC時刻を時:分に変更

* 周辺のリファクタリング

* 変数名を変更

* コメントを削除

* 命名変更・不使用部分削除

Co-authored-by: noyanyan <[email protected]>
  • Loading branch information
no-yan and noyanyan authored Apr 25, 2021
1 parent 0903b4e commit 344598a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 45 deletions.
94 changes: 56 additions & 38 deletions frontend/src/components/RankingTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,58 +21,76 @@ interface RankingTableRowProps {
problems: ProblemInfo[];
}

type RowTemplateProps = {
ranking: number;
accountName: string;
score: number;
penalty: number;
};
const RowTemplate: React.VFC<RowTemplateProps> = ({
ranking,
accountName,
score,
penalty,
}) => (
<>
<td className="align-middle text-center">{ranking}</td>
<td className="align-middle font-weight-bold">{accountName}</td>
<td className="align-middle text-center">
<div className="font-weight-bold text-primary">{score}</div>
<div className="text-muted">{formatSecondToMMSS(penalty)}</div>
</td>
</>
);

type PlayerStatusProps = {
problemId: number;
point: number;
time: number;
};
const PlayerStatusOfProblem: React.VFC<PlayerStatusProps> = ({
problemId,
point,
time,
}) => (
<td key={problemId} className="align-middle text-center">
<div className="font-weight-bold text-success">{point}</div>
<div className="text-muted">{formatSecondToMMSS(time)}</div>
</td>
);

export const RankingTableRow: React.FC<RankingTableRowProps> = ({
account,
isMe,
problems,
}) => {
const probElement = [];
for (let i = 0; i < problems.length; i++) {
if (account.acceptList.some((ac: any) => ac === i)) {
//null | number[] ?
probElement.push(
<td>
<p className={'contestPage-ranking-submitResult'}>AC</p>
<p className={'contestPage-ranking-submitTime'}>
{formatSecondToMMSS(account.acceptTimeList[i])}
</p>
</td>
);
} else {
probElement.push(<td> </td>);
}
}

return (
<tr className={isMe ? 'table-info' : undefined}>
<td className="align-middle text-center">{account.ranking}</td>
<td className="align-middle font-weight-bold">{account.accountName}</td>
<td className="align-middle text-center">
<div className="font-weight-bold text-primary">{account.score}</div>
<div className="text-muted">{account.penalty}</div>
</td>
{problems.map((problems) => {
const i = account.acceptList.findIndex(
(v) => v === problems.indexOfContest
<RowTemplate
ranking={account.ranking}
accountName={account.accountName}
score={account.score}
penalty={account.penalty}
/>

{problems.map((problem) => {
const accountAcceptIdx = account.acceptList.findIndex(
(v) => v === problem.indexOfContest
);
if (i === -1) {
if (accountAcceptIdx === -1) {
return (
<td key={problems.id} className="align-middle text-center">
<td key={problem.id} className="align-middle text-center">
-
</td>
);
}
return (
<td key={problems.id} className="align-middle text-center">
<div className="font-weight-bold text-success">
{problems.point}
</div>
<div className="text-muted">
{formatSecondToMMSS(
account.acceptTimeList[problems.indexOfContest]
)}
</div>
</td>
<PlayerStatusOfProblem
key={problem.id}
problemId={problem.id}
point={problem.point}
time={account.acceptTimeList[problem.indexOfContest]}
/>
);
})}
</tr>
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/pages/ContestPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ const RankingElement: React.FC<RankingElementProps> = ({
getRanking();
}

useEffect(() => {
getRanking();
}, []);

let myRank = '';
if (ranking?.requestAccountRank) {
myRank = `順位: ${ranking.requestAccountRank}`;
}

useEffect(() => {
getRanking();
}, []);

return (
<>
<p>{myRank}</p>
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,18 @@ export interface RankingInfo {
/**
* 順位表に表示するためのアカウント情報
*/
// AccountRankingInfoとRankingInfoAccountの区別が付きづらい User_StandingDataなどは?
// ユーザーの順位に関係するデータだとすぐわかるようにしたいです
export interface RankingInfoAccount {
accountName: string;
/**
* ACした問題リスト
*/
acceptList: unknown[];
acceptList: number[];
/**
* このアカウントの現在順位
*/
ranking: any;
ranking: number;
/**
* 提出までに経過した秒数
*/
Expand Down Expand Up @@ -141,4 +143,4 @@ export interface ProblemInfo {
export interface AccountRankingInfo {
accounts: AccountInfo[];
validAccountNum: number;
}
}

0 comments on commit 344598a

Please sign in to comment.