diff options
| author | Brendan F <EpicWolverine@users.noreply.github.com> | 2023-05-14 23:12:27 -0700 |
|---|---|---|
| committer | Brendan F <EpicWolverine@users.noreply.github.com> | 2023-05-14 23:12:27 -0700 |
| commit | 737344a72d23dc97b0d0e73cc4ab7fdffd0fbf49 (patch) | |
| tree | 2a915b59ab29ac79012ca3345999d9e23562d1f9 /src/components/Game | |
| parent | b19a001171bd8197a30f397091d67eba5e4c1111 (diff) | |
Merge in react app code
From sluchajfun and youtube-heardle-template
Diffstat (limited to 'src/components/Game')
| -rw-r--r-- | src/components/Game/index.styled.ts | 8 | ||||
| -rw-r--r-- | src/components/Game/index.tsx | 65 |
2 files changed, 73 insertions, 0 deletions
diff --git a/src/components/Game/index.styled.ts b/src/components/Game/index.styled.ts new file mode 100644 index 0000000..7860f98 --- /dev/null +++ b/src/components/Game/index.styled.ts @@ -0,0 +1,8 @@ +import styled from "styled-components"; + +export const Buttons = styled.div` + margin-top: 5%; + display: flex; + justify-content: space-between; + width: 100%; +`; diff --git a/src/components/Game/index.tsx b/src/components/Game/index.tsx new file mode 100644 index 0000000..84ca282 --- /dev/null +++ b/src/components/Game/index.tsx @@ -0,0 +1,65 @@ +import React from "react"; + +import { GuessType } from "../../types/guess"; +import { Song } from "../../types/song"; +import { playTimes } from "../../constants"; + +import { Button, Guess, Player, Search, Result } from "../"; + +import * as Styled from "./index.styled"; + +interface Props { + guesses: GuessType[]; + todaysSolution: any; + currentTry: number; + didGuess: boolean; + setSelectedSong: React.Dispatch<React.SetStateAction<Song | undefined>>; + skip: () => void; + guess: () => void; +} + +export function Game({ + guesses, + todaysSolution, + currentTry, + didGuess, + setSelectedSong, + skip, + guess, +}: Props) { + if (didGuess || currentTry === 6) { + return ( + <Result + didGuess={didGuess} + currentTry={currentTry} + todaysSolution={todaysSolution} + guesses={guesses} + /> + ); + } + return ( + <> + {guesses.map((guess: GuessType, index) => ( + <Guess + key={index} + guess={guess} + isCorrect={guess.isCorrect} + active={index === currentTry} + /> + ))} + <Player id={todaysSolution.youtubeId} currentTry={currentTry} /> + <Search currentTry={currentTry} setSelectedSong={setSelectedSong} /> + + <Styled.Buttons> + <Button onClick={skip}> + {currentTry === 5 + ? "Give Up" + : `Skip +${playTimes[currentTry] / 1000}s`} + </Button> + <Button variant="green" onClick={guess}> + Submit + </Button> + </Styled.Buttons> + </> + ); +} |
