From 737344a72d23dc97b0d0e73cc4ab7fdffd0fbf49 Mon Sep 17 00:00:00 2001 From: Brendan F Date: Sun, 14 May 2023 23:12:27 -0700 Subject: Merge in react app code From sluchajfun and youtube-heardle-template --- src/components/Result/index.styled.ts | 33 ++++++++++++++++ src/components/Result/index.tsx | 74 +++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 src/components/Result/index.styled.ts create mode 100644 src/components/Result/index.tsx (limited to 'src/components/Result') diff --git a/src/components/Result/index.styled.ts b/src/components/Result/index.styled.ts new file mode 100644 index 0000000..92d51f5 --- /dev/null +++ b/src/components/Result/index.styled.ts @@ -0,0 +1,33 @@ +import styled from "styled-components"; + +export const ResultTitle = styled.h1` + @media (max-width: 768px) { + text-align: center; + width: 100%; + } +`; + +export const Tries = styled.h4` + @media (max-width: 768px) { + text-align: center; + width: 100%; + } + + margin-top: 0; +`; + +export const SongTitle = styled.h3` + @media (max-width: 768px) { + text-align: center; + width: 100%; + } + + margin-top: 0; +`; + +export const TimeToNext = styled.h4` + @media (max-width: 768px) { + text-align: center; + width: 100%; + } +`; diff --git a/src/components/Result/index.tsx b/src/components/Result/index.tsx new file mode 100644 index 0000000..40a95fb --- /dev/null +++ b/src/components/Result/index.tsx @@ -0,0 +1,74 @@ +import React from "react"; + +import { Song } from "../../types/song"; +import { GuessType } from "../../types/guess"; +import { scoreToEmoji } from "../../helpers"; + +import { Button } from "../Button"; +import { YouTube } from "../YouTube"; + +import * as Styled from "./index.styled"; + +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 + ); + + const textForTry = ["Wow!", "Super!", "Congrats!", "Nice!"]; + + if (didGuess) { + const copyResult = React.useCallback(() => { + navigator.clipboard.writeText(scoreToEmoji(guesses)); + }, [guesses]); + + return ( + <> + {textForTry[currentTry - 1]} + + Todays song is {todaysSolution.artist} -{" "} + {todaysSolution.name} + + + You guessed it in {currentTry} {currentTry === 1 ? 'try' : 'tries'} + + + + + Remember to come back in {hoursToNextDay}{" "} hours! + + + ); + } else { + return ( + <> + Unfortunately, thats wrong + + Todays song is {todaysSolution.artist} -{" "} + {todaysSolution.name} + + + + Try again in {hoursToNextDay}{" "} hours + + + ); + } +} -- cgit v1.2.3