Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getRatingColor, MemberStats, UserProfile } from '~/libs/core'
import { IconOutline } from '~/libs/ui'

import { useFetchActiveTracks } from '../../../hooks'
import { WinnerIcon } from '../../../lib'
import { formatPlural, WinnerIcon } from '../../../lib'
import { MemberProfileContextValue, useMemberProfileContext } from '../../../member-profile/MemberProfile.context'

import styles from './MemberStatsBlock.module.scss'
Expand Down Expand Up @@ -45,13 +45,18 @@ const MemberStatsBlock: FC<MemberStatsBlockProps> = props => {
<div className={styles.trackDetails}>
{!track.isDSTrack && ((track.submissions || track.wins) > 0) && (
<>
<WinnerIcon className='icon-xxxl' />
{track.wins > 0 && (
<WinnerIcon className='icon-xxxl' />
)}
<span className={styles.trackStats}>
<span className={styles.count}>
{track.wins || track.submissions}
</span>
<span className={styles.label}>
{track.wins > 0 ? 'Wins' : 'Submissions'}
{formatPlural(
track.wins || track.submissions || 0,
track.wins > 0 ? 'Win' : 'Submission',
)}
</span>
</span>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { find, get } from 'lodash'

import { getRatingColor } from '~/libs/core'

import { numberToFixed } from '../../../lib'
import { formatPlural, numberToFixed } from '../../../lib'
import { TracksSummaryStats } from '../../../config'

import styles from './StatsSummaryBlock.module.scss'
Expand Down Expand Up @@ -49,7 +49,10 @@ const StatsSummaryBlock: FC<StatsSummaryBlockProps> = props => {
</span>
<span className={styles.summaryItemLabel}>
<span className='body-small'>
{props.trackTitle === 'Single Round Match' ? 'Competitions' : 'Challenges'}
{formatPlural(
props.challenges || 0,
props.trackTitle === 'Single Round Match' ? 'Competition' : 'Challenge',
)}
</span>
</span>
</div>
Expand All @@ -61,7 +64,7 @@ const StatsSummaryBlock: FC<StatsSummaryBlockProps> = props => {
</span>
<span className={styles.summaryItemLabel}>
<span className='body-small'>
Wins
{formatPlural(props.wins || 0, 'Win')}
</span>
</span>
</div>
Expand All @@ -73,7 +76,7 @@ const StatsSummaryBlock: FC<StatsSummaryBlockProps> = props => {
</span>
<span className={styles.summaryItemLabel}>
<span className='body-small'>
Submissions
{formatPlural(props.submissions || 0, 'Submission')}
</span>
</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import classNames from 'classnames'

import { IconSolid } from '~/libs/ui'

import { subTrackLabelToHumanName, WinnerIcon } from '../../../lib'
import { formatPlural, subTrackLabelToHumanName, WinnerIcon } from '../../../lib'

import styles from './SubTrackSummaryCard.module.scss'

Expand All @@ -29,7 +29,9 @@ const SubTrackSummaryCard: FC<SubTrackSummaryCardProps> = props => (
{props.wins}
</span>
<span className={styles.statsItemLabel}>
<span className='label'>wins</span>
<span className='label'>
{formatPlural(props.wins || 0, 'Win')}
</span>
</span>
</div>
)}
Expand All @@ -38,7 +40,9 @@ const SubTrackSummaryCard: FC<SubTrackSummaryCardProps> = props => (
{props.submissions}
</span>
<span className={styles.statsItemLabel}>
<span className='label'>submissions</span>
<span className='label'>
{formatPlural(props.submissions || 0, 'Submission')}
</span>
</span>
</div>
</div>
Expand Down
12 changes: 12 additions & 0 deletions src/apps/profiles/src/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,15 @@ export function isValidURL(urlToValidate: string): boolean {

return true
}

/**
* Creates the string with the number of items and the word describing the item
* possibly in plural form.
*
* @param {number} count - The number of entities
* @param {string} baseWord - The base word that describes the entity
* @returns {string}
*/
export function formatPlural(count: number, baseWord: string): string {
return `${baseWord}${count === 1 ? '' : 's'}`
}