Skip to content

Commit

Permalink
add medals to share text
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-james-watson committed Jan 30, 2022
1 parent e62ce70 commit 49c020f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
15 changes: 14 additions & 1 deletion components/game-over.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ interface Props {

const defaultShareText = "Share";

function getMedal(score: number): string {
if (score >= 20) {
return "🥇 ";
} else if (score >= 10) {
return "🥈 ";
} else if (score >= 1) {
return "🥉 ";
}
return "";
}

export default function GameOver(props: Props) {
const { highscore, resetGame, score } = props;

Expand All @@ -25,7 +36,9 @@ export default function GameOver(props: Props) {

const share = React.useCallback(async () => {
await navigator?.clipboard?.writeText(
`🏛️ wikitrivia.tomjwatson.com\n\nStreak: ${score}\nBest Streak: ${highscore}`
`🏛️ wikitrivia.tomjwatson.com\n\n${getMedal(
score
)}Streak: ${score}\n${getMedal(highscore)}Best Streak: ${highscore}`
);
setShareText("Copied");
setTimeout(() => {
Expand Down
8 changes: 5 additions & 3 deletions components/instructions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ export default function Instructions(props: Props) {
<div className={styles.instructions}>
<div className={styles.wrapper}>
<h2>Place the cards on the timeline in the correct order.</h2>
<div className={styles.highscoreWrapper}>
<Score score={highscore} title="Best streak" />
</div>
{highscore !== 0 && (
<div className={styles.highscoreWrapper}>
<Score score={highscore} title="Best streak" />
</div>
)}
<Button onClick={start} text="Start game" />
<div className={styles.about}>
<div>
Expand Down
1 change: 1 addition & 0 deletions styles/instructions.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
color: $text-light;
font-style: italic;
text-transform: uppercase;
margin-bottom: 40px;
}

.highscoreWrapper {
Expand Down
2 changes: 1 addition & 1 deletion styles/score.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
border-radius: $box-border-radius;
padding: 10px 24px;
text-align: left;
width: 140px;

.title {
font-weight: 700;
Expand All @@ -16,6 +15,7 @@
}

.value {
display: flex;
font-weight: 700;
font-size: 24px;
}
Expand Down

0 comments on commit 49c020f

Please sign in to comment.