aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/Result/index.tsx
diff options
context:
space:
mode:
authorBrendan F <EpicWolverine@users.noreply.github.com>2023-05-14 23:12:27 -0700
committerBrendan F <EpicWolverine@users.noreply.github.com>2023-05-14 23:12:27 -0700
commit737344a72d23dc97b0d0e73cc4ab7fdffd0fbf49 (patch)
tree2a915b59ab29ac79012ca3345999d9e23562d1f9 /src/components/Result/index.tsx
parentb19a001171bd8197a30f397091d67eba5e4c1111 (diff)
Merge in react app code
From sluchajfun and youtube-heardle-template
Diffstat (limited to 'src/components/Result/index.tsx')
-rw-r--r--src/components/Result/index.tsx74
1 files changed, 74 insertions, 0 deletions
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 (
+ <>
+ <Styled.ResultTitle>{textForTry[currentTry - 1]}</Styled.ResultTitle>
+ <Styled.SongTitle>
+ Todays song is {todaysSolution.artist} -{" "}
+ {todaysSolution.name}
+ </Styled.SongTitle>
+ <Styled.Tries>
+ You guessed it in {currentTry} {currentTry === 1 ? 'try' : 'tries'}
+ </Styled.Tries>
+ <YouTube id={todaysSolution.youtubeId} />
+ <Button onClick={copyResult} variant="green">
+ Copy results
+ </Button>
+ <Styled.TimeToNext>
+ Remember to come back in {hoursToNextDay}{" "} hours!
+ </Styled.TimeToNext>
+ </>
+ );
+ } else {
+ return (
+ <>
+ <Styled.ResultTitle>Unfortunately, thats wrong</Styled.ResultTitle>
+ <Styled.SongTitle>
+ Todays song is {todaysSolution.artist} -{" "}
+ {todaysSolution.name}
+ </Styled.SongTitle>
+ <YouTube id={todaysSolution.youtubeId} />
+ <Styled.TimeToNext>
+ Try again in {hoursToNextDay}{" "} hours
+ </Styled.TimeToNext>
+ </>
+ );
+ }
+}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage