From d2cc71a654f743209faa7aa475659d675ebfcb36 Mon Sep 17 00:00:00 2001 From: Brendan F Date: Sun, 25 Jun 2023 23:55:26 -0700 Subject: Reduce repeated code in Results --- src/components/Result/index.tsx | 74 +++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/components/Result/index.tsx b/src/components/Result/index.tsx index 2e1e03a..3b3b06c 100644 --- a/src/components/Result/index.tsx +++ b/src/components/Result/index.tsx @@ -8,6 +8,55 @@ import { Button } from "../Button"; import { MiniYouTubePlayer } from "../MiniYouTubePlayer"; import * as Styled from "./index.styled"; +import { theme } from "../../constants"; + +interface SolutionProps { + didGuess: boolean; + currentTry: number; + todaysSolution: Song; +} + +function Solution({ + didGuess, + todaysSolution, + currentTry, +}: SolutionProps) { + return ( + <> + + Today's song is {todaysSolution.artist} - {todaysSolution.name} + + {didGuess && + + You guessed it in {currentTry} {currentTry === 1 ? 'try' : 'tries'}. + + } + + + ); +} + +interface ShareButtonProps { + guesses: GuessType[]; + variant?: keyof typeof theme; +} + +function ShareButton({ + guesses, + variant +}:ShareButtonProps) { + const copyResult = React.useCallback(() => { + navigator.clipboard.writeText(scoreToEmoji(guesses)); + }, [guesses]); + + return ( + <> + + + ) +} interface Props { didGuess: boolean; @@ -30,25 +79,13 @@ export function Result({ 60 ); - const copyResult = React.useCallback(() => { - navigator.clipboard.writeText(scoreToEmoji(guesses)); - }, [guesses]); - if (didGuess) { const textForTry = ["Perfect!", "Wow!", "Super!", "Congrats!", "Nice!"]; return ( <> {textForTry[currentTry - 1]} - - Today's song is {todaysSolution.artist} - {todaysSolution.name} - - - You guessed it in {currentTry} {currentTry === 1 ? 'try' : 'tries'}. - - - + + Remember to come back in {hoursToNextDay} hours! @@ -58,13 +95,8 @@ export function Result({ return ( <> Unfortunately, thats wrong. - - Today's song is {todaysSolution.artist} - {todaysSolution.name} - - - + + Try again in {hoursToNextDay} hours. -- cgit v1.2.3