1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
import React 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";
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 copyResult = React.useCallback(() => {
navigator.clipboard.writeText(scoreToEmoji(guesses));
}, [guesses]);
if (didGuess) {
const textForTry = ["Perfect!", "Wow!", "Super!", "Congrats!", "Nice!"];
return (
<>
<Styled.ResultTitle>{textForTry[currentTry - 1]}</Styled.ResultTitle>
<Styled.SongTitle>
Today's song is {todaysSolution.artist} - {todaysSolution.name}
</Styled.SongTitle>
<Styled.Tries>
You guessed it in {currentTry} {currentTry === 1 ? 'try' : 'tries'}.
</Styled.Tries>
<MiniYouTubePlayer 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>
Today's song is {todaysSolution.artist} - {todaysSolution.name}
</Styled.SongTitle>
<MiniYouTubePlayer id={todaysSolution.youtubeId} />
<Button onClick={copyResult} variant="red">
Copy results
</Button>
<Styled.TimeToNext>
Try again in {hoursToNextDay} hours.
</Styled.TimeToNext>
</>
);
}
}
|