import React, { useState } from 'react'; import { Song } from "../../types/song"; import { GuessType } from "../../types/guess"; import { scoreToEmoji } from "../../helpers"; 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 result = scoreToEmoji(guesses); const [buttonText, setButtonText] = useState('Share Results'); const handleClick = React.useCallback(() => { // The Windows share sheet is dumb and doesn't have a copy function. const windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE']; const onWindows = windowsPlatforms.indexOf(window.navigator.platform) !== -1; if (navigator.share !== undefined && !onWindows) { navigator.share({text: result}) } else if (navigator.clipboard !== undefined) { navigator.clipboard.writeText(result) setButtonText('Copied!'); } else { setButtonText('Failed to open share menu or copy'); } }, [guesses]); return ( <> ) } interface Props { didGuess: boolean; currentTry: number; todaysSolution: Song; guesses: GuessType[]; } export function Result({ didGuess, todaysSolution, guesses, currentTry, }: Props) { const hoursToNextDay = Math.floor( (new Date(new Date().setHours(24, 0, 0, 0)).getTime() - new Date().getTime()) / 1000 / 60 / 60 ); if (didGuess) { const textForTry = ["Perfect!", "Wow!", "Super!", "Congrats!", "Nice!"]; return ( <> {textForTry[currentTry - 1]} Remember to come back in {hoursToNextDay} hours! ); } else { return ( <> Unfortunately, thats wrong. Try again in {hoursToNextDay} hours. ); } }