Skip to content

Commit

Permalink
Merge pull request #857 from hackclub/fix-pluralization
Browse files Browse the repository at this point in the history
Fix missing or bugged pluralizeation using lib
  • Loading branch information
maxwofford authored Nov 25, 2024
2 parents ec20b4b + 37a56a6 commit 8d10b87
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/app/harbor/battles/battles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { HsSession } from '@/app/utils/auth'
import SpeechToText from '@/components/speech-to-text'
import Blessed from './blessed'
import Cursed from './cursed'
import pluralize from '../../../../lib/pluralize'

interface Matchup {
project1: Ships
Expand Down Expand Up @@ -490,8 +491,8 @@ export default function Matchups({ session }: { session: HsSession }) {

{voteBalance > 0 && (
<div className="flex justify-center items-center space-x-4">
{voteBalance} more vote{voteBalance == 1 ? '' : 's'} until your
next ship's payout!
{voteBalance} more {pluralize(voteBalance, 'vote', false)} until
your next ship's payout!
</div>
)}
</header>
Expand Down
20 changes: 11 additions & 9 deletions src/components/ui/ship-pill-cluster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Pill from './pill'

import DoubloonsImage from '/public/doubloon.svg'
import Image from 'next/image'
import pluralize from '../../../lib/pluralize'

export default function ShipPillCluster({
ship,
Expand All @@ -15,11 +16,12 @@ export default function ShipPillCluster({
? shipChains.get(ship.wakatimeProjectNames.join(','))
: null
const shipUpdateCount = shipUpdates ? shipUpdates.length - 1 : null
const unit = ship.doubloonPayout == 1 || '1' ? 'Doubloon' : 'Doubloons'
const roundedPayout = Math.floor(ship.doubloonPayout)
const roundedHr = ship.total_hours?.toFixed(1)
return (
<>
{ship.shipStatus === 'shipped' ? (
<Pill msg={`${ship.total_hours?.toFixed(1) ?? 0} hr`} glyph="clock" />
<Pill msg={pluralize(roundedHr, 'hr', true)} glyph="clock" />
) : (
<Pill msg="pending ship" glyph="clock" />
)}
Expand All @@ -28,17 +30,19 @@ export default function ShipPillCluster({
(ship.voteRequirementMet ? (
ship.doubloonPayout != null ? (
<Pill
msg={`${Math.floor(ship.doubloonPayout)} ${unit}`}
msg={pluralize(roundedPayout, 'doubloon', true)}
color="green"
glyphImage={
<Image src={DoubloonsImage} alt="doubloons" height={20} />
}
/>
) : (
<Pill
msg={`Awaiting ${10 - ship.matchups_count} more vote${
10 - ship.matchups_count === 1 ? '' : 's'
} from other pirates…`}
msg={`Awaiting ${10 - ship.matchups_count} more ${pluralize(
10 - ship.matchups_count,
'vote',
false,
)} from other pirates…`}
color="blue"
glyph="event-add"
percentage={Math.max(ship.matchups_count * 10, 5)}
Expand All @@ -54,9 +58,7 @@ export default function ShipPillCluster({

{shipUpdateCount && shipUpdateCount > 0 ? (
<Pill
msg={`${shipUpdateCount} Ship update${
shipUpdateCount === 1 ? '' : 's'
}`}
msg={pluralize(shipUpdateCount, 'update', true)}
color="purple"
glyph="reply"
glyphStyles={{ transform: 'scaleX(-1)' }}
Expand Down

0 comments on commit 8d10b87

Please sign in to comment.