Skip to content

Commit

Permalink
refactor: Update Score and Rank components to use RankPayload interface
Browse files Browse the repository at this point in the history
  • Loading branch information
drikusroor committed Jun 25, 2024
1 parent c990145 commit aaf7ce4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const Header: React.FC<HeaderProps> = ({
<div className="results">
<Score
score={totalScore}
scoreClass={scoreDisplayConfig.scoreClass}
rank={{ class: scoreDisplayConfig.scoreClass, text: '' }}
label={scoreDisplayConfig.scoreLabel}
/>
<Social
Expand Down
11 changes: 3 additions & 8 deletions frontend/src/components/ExperimentCollection/Score/Score.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import React from "react";

import Rank from "@/components/Rank/Rank";
import Rank, { RankPayload } from "@/components/Rank/Rank";
import useAnimatedScore from "@/hooks/useAnimatedScore";

interface ScoreProps {
score: number;
label: string;
scoreClass: string; // The rank class, e.g. diamond, platinum, gold, silver, bronze, plastic
rank: RankPayload;
}

const Score = ({ score, label, scoreClass }: ScoreProps) => {
const Score = ({ score, label, rank }: ScoreProps) => {
const currentScore = useAnimatedScore(score);

const rank = {
class: scoreClass,
text: "",
}

return (
<div className="score">
<Rank rank={rank} />
Expand Down
26 changes: 12 additions & 14 deletions frontend/src/components/Rank/Rank.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import classNames from "classnames";

export interface RankPayload {
class: string;
class: string | "diamond" | "platinum" | "gold" | "silver" | "bronze" | "plastic";
text: string;
}

Expand All @@ -10,18 +10,16 @@ interface RankProps {
}

// Rank shows a decorated representation of a rank
const Rank = ({ rank }: RankProps) => {
return (
<div
className={classNames("aha__rank", rank.class, {
offsetCup: rank.text,
})}
data-testid="rank"
>
<div className="cup-animation" data-testid="cup-animation" />
<h4 data-testid="rank-text">{rank.text}</h4>
</div >
);
};
const Rank = ({ rank }: RankProps) => (
<div
className={classNames("aha__rank", rank.class, {
offsetCup: rank.text,
})}
data-testid="rank"
>
<div className="cup-animation" data-testid="cup-animation" />
<h4 data-testid="rank-text">{rank.text}</h4>
</div >
);

export default Rank;
9 changes: 6 additions & 3 deletions frontend/src/stories/ScoreV2.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@ export default {
layout: "fullscreen",
},
argTypes: {
scoreClass: {
"rank.class": {
control: {
type: "select",
},
options: ['diamond', 'platinum', 'gold', 'silver', 'bronze', 'plastic'],
}
},
}
};

function getScoreData(overrides = {}) {
return {
score: 100,
label: "points",
scoreClass: "scoreCirclePositive",
rank: {
class: "gold",
text: "Gold",
},
...overrides,
};
}
Expand Down

0 comments on commit aaf7ce4

Please sign in to comment.