Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

順位表の時間表示を一部修正  #182

Merged
merged 6 commits into from
Apr 25, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 76 additions & 31 deletions frontend/src/components/RankingTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,85 @@ interface RankingTableRowProps {
problems: ProblemInfo[];
}

type RowTemplateProps = {
// isMe: boolean;
ShopOne marked this conversation as resolved.
Show resolved Hide resolved
ranking: number;
accountName: string;
score: number;
penalty: number;
};
const RowTemplate: React.VFC<RowTemplateProps> = ({
// isMe,
ranking,
accountName,
score,
penalty,
}) => (
<>
{/* <td className={isMe ? 'table-info' : undefined}></td> */}
ShopOne marked this conversation as resolved.
Show resolved Hide resolved
<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>
</>
);

const PointAndAcTime = (time: number) => (
<td>
<p className={'contestPage-ranking-submitResult'}>AC</p>
<p className={'contestPage-ranking-submitTime'}>
{formatSecondToMMSS(time)}
</p>
</td>
);

type PlayerStatusProps = {
problemId: number;
point: number;
time: number;
};
const PlayerStatusOn_aProblem: React.VFC<PlayerStatusProps> = ({
ShopOne marked this conversation as resolved.
Show resolved Hide resolved
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)) {
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>);
}
}
// 使われてない
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const probList = problems.map((_, i) =>
account.acceptList.some((ac: number) => ac === i) ? (
PointAndAcTime(account.acceptTimeList[i])
) : (
<td> </td>
)
);
ShopOne marked this conversation as resolved.
Show resolved Hide resolved

// account.acceptListが(true|false)[]で与えられたら処理は簡単になる
ShopOne marked this conversation as resolved.
Show resolved Hide resolved

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>
<RowTemplate
// isMe={isMe}
ranking={account.ranking}
accountName={account.accountName}
score={account.score}
penalty={account.penalty}
/>

{problems.map((problems) => {
// 名前が衝突しています。動作が変わると嫌なのでとりあえずこのまま
ShopOne marked this conversation as resolved.
Show resolved Hide resolved
const i = account.acceptList.findIndex(
(v) => v === problems.indexOfContest
);
Expand All @@ -62,16 +111,12 @@ export const RankingTableRow: React.FC<RankingTableRowProps> = ({
);
}
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>
<PlayerStatusOn_aProblem
key={problems.id}
problemId={problems.id}
point={problems.point}
time={account.acceptTimeList[problems.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などは?
// ユーザーの順位に関係するデータだとすぐわかるようにしたいです
ShopOne marked this conversation as resolved.
Show resolved Hide resolved
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;
}
}