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

Convert game header component to typescript #12050

Merged
merged 4 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
60 changes: 0 additions & 60 deletions resources/js/mp-history/game-header.coffee

This file was deleted.

80 changes: 80 additions & 0 deletions resources/js/mp-history/game-header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

import BeatmapsetCover from 'components/beatmapset-cover';
import Mod from 'components/mod';
import StringWithComponent from 'components/string-with-component';
import TimeWithTooltip from 'components/time-with-tooltip';
import BeatmapJson from 'interfaces/beatmap-json';
import BeatmapsetJson from 'interfaces/beatmapset-json';
import LegacyMatchGameJson from 'interfaces/legacy-match-game-json';
import { route } from 'laroute';
import * as React from 'react';
import { getArtist, getTitle } from 'utils/beatmapset-helper';
import { classWithModifiers } from 'utils/css';
import { trans } from 'utils/lang';

interface Props {
beatmap: BeatmapJson;
beatmapset: BeatmapsetJson;
game: LegacyMatchGameJson;
}

export default function GameHeader(props: Props) {
const timeFormat = 'LTS';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be outside of the function


let title = getTitle(props.beatmapset);
const version = props.beatmap.version;
if (version != null) {
title += ` [${version}]`;
}

const startTime = (<TimeWithTooltip dateTime={props.game.start_time} format={timeFormat} />);
const endTime = props.game.end_time != null
? (<TimeWithTooltip dateTime={props.game.end_time} format={timeFormat} />)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the () isn't needed

: null;

return (
<a
className='mp-history-game__header'
href={props.beatmap.id != null ? route('beatmaps.show', { beatmap: props.beatmap.id }) : ''}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined is probably better than empty string (which links to current page instead)

<BeatmapsetCover
beatmapset={props.beatmapset}
modifiers='full'
size='cover' />
<div className='mp-history-game__header-overlay' />
<div className='mp-history-game__stats-box'>
<span className='mp-history-game__stat'>
{endTime != null
? <StringWithComponent
mappings={{
endTime,
startTime,
}}
pattern=':startTime - :endTime' />
: <StringWithComponent
mappings={{
inProgress: trans('matches.match.in-progress'),
startTime,
}}
pattern=':startTime :inProgress' />}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I forgot to mention - I'm kinda inventing with this one because I don't think anything else does ad-hoc patterns like this (at least I can't grep any) but maybe this is better than the previous code which was kinda hard to parse?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a plain <>{startTime} - {endTime}</> and <>{startTime} {trans...}</> would probably be just as readable?

</span>
<span className='mp-history-game__stat'>{trans(`beatmaps.mode.${props.game.mode}`)}</span>
<span className='mp-history-game__stat'>{trans(`matches.game.scoring-type.${props.game.scoring_type}`)}</span>
</div>
<div className='mp-history-game__metadata-box'>
<h1 className={classWithModifiers('mp-history-game__metadata', ['title'])}>{title}</h1>
<h2 className={classWithModifiers('mp-history-game__metadata', ['artist'])}>{getArtist(props.beatmapset)}</h2>
</div>
<div className='mp-history-game__mods'>
{props.game.mods.map((mod) => (<Mod key={mod} mod={{ acronym: mod }} />))}
</div>
<div
className='mp-history-game__team-type'
style={{
backgroundImage: `url(/images/badges/team-types/${props.game.team_type}.svg`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing closing )

}}
title={trans(`matches.match.team-types.${props.game.team_type}`)} />
</a>
);
}
2 changes: 1 addition & 1 deletion resources/js/mp-history/game.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as React from 'react'
import { div, span, strong } from 'react-dom-factories'
import { formatNumber } from 'utils/html'
import { trans, transExists } from 'utils/lang'
import { GameHeader } from './game-header'
import GameHeader from './game-header'
import { Score } from './score'

el = React.createElement
Expand Down