diff --git a/projects/website/src/common/change.tsx b/projects/website/src/common/change.tsx index 17e0ead..888929a 100644 --- a/projects/website/src/common/change.tsx +++ b/projects/website/src/common/change.tsx @@ -1,19 +1,44 @@ import React from "react"; +import { formatNumberWithCommas, formatPp } from "@ssr/common/utils/number-utils"; -/** - * Renders the change for a stat. - * - * @param change the change - * @param isPp whether the stat is pp - * @param formatValue the function to format the value - */ -export function renderChange(change: number | undefined, isPp: boolean, formatValue: (value: number) => string) { +type ChangeProps = { + /** + * The amount the value changed + */ + change: number | undefined; + + /** + * The function to format the value + * @param value + */ + formatValue?: (value: number) => string; + + /** + * Whether the number is a pp number + */ + isPp?: boolean; + + /** + * Should we use colors? + */ + showColors?: boolean; +}; + +export function Change({ change, formatValue, isPp, showColors }: ChangeProps) { if (change === 0 || (change && change > 0 && change < 0.01) || change === undefined) { return null; } + // Default formats + if (!formatValue) { + formatValue = formatNumberWithCommas; + if (isPp) { + formatValue = formatPp; + } + } + return ( -
0 ? "text-green-400" : "text-red-400"}`}> +
0 ? "text-green-400" : "text-red-400")}`}> {change > 0 ? "+" : ""} {`${formatValue(change)}${isPp ? "pp" : ""}`}
diff --git a/projects/website/src/components/score/hand-accuracy.tsx b/projects/website/src/components/score/hand-accuracy.tsx new file mode 100644 index 0000000..864c56b --- /dev/null +++ b/projects/website/src/components/score/hand-accuracy.tsx @@ -0,0 +1,39 @@ +import Tooltip from "@/components/tooltip"; +import { Change } from "@/common/change"; +import ScoreSaberScore from "@ssr/common/score/impl/scoresaber-score"; +import { capitalizeFirstLetter } from "@/common/string-utils"; + +type HandAccuracyProps = { + /** + * The score to get the hand accuracy from + */ + score: ScoreSaberScore; + + /** + * The hand to get the hand accuracy from + */ + hand: "left" | "right"; +}; + +export function HandAccuracy({ score, hand }: HandAccuracyProps) { + if (!score.additionalData) { + return undefined; + } + const { handAccuracy } = score.additionalData; + const scoreImprovement = score.additionalData.scoreImprovement; + const previousHandAccuracy = scoreImprovement ? handAccuracy[hand] - scoreImprovement.handAccuracy[hand] : undefined; + + const formattedHand = capitalizeFirstLetter(hand); + return ( +{handAccuracy[hand].toFixed(2)}
+{formatPp(pp)}pp
+{formatPp(pp)}pp
+ {previousAccuracy &&
{acc.toFixed(2)}% {modCount > 0 &&
{formatNumberWithCommas(Number(score.score.toFixed(0)))}
- {scoreImprovement && renderChange(scoreImprovement.score, false, formatNumberWithCommas)} + {scoreImprovement &&{handAccuracy.left.toFixed(2)}
- {scoreImprovement && renderChange(scoreImprovement.handAccuracy.left, false, num => num.toFixed(2))} -{handAccuracy.right.toFixed(2)}
- {scoreImprovement && renderChange(scoreImprovement.handAccuracy.right, false, num => num.toFixed(2))} -