diff options
| author | Pinapelz <yukais@pinapelz.com> | 2026-06-03 17:22:48 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2026-06-03 17:22:48 -0700 |
| commit | 14172f9dd64ce91ba5cf51f82c53deb6a81d68a6 (patch) | |
| tree | 5e12ce4e30ecaed9a2aac48d2959d99a4d8b4ef7 /src/pages/UnlimitedPage.tsx | |
| parent | 818db3ef4aadf489dba5ba8ba4f3bb4e150f0b22 (diff) | |
create daily/unlimited mode, CDN audio file for daily mode
Diffstat (limited to 'src/pages/UnlimitedPage.tsx')
| -rw-r--r-- | src/pages/UnlimitedPage.tsx | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/pages/UnlimitedPage.tsx b/src/pages/UnlimitedPage.tsx new file mode 100644 index 0000000..761d2b9 --- /dev/null +++ b/src/pages/UnlimitedPage.tsx @@ -0,0 +1,78 @@ +import React from "react"; + +import { Song } from "../types/song"; +import { getSelectSolution } from "../helpers/fetchSolution"; +import { useGameState } from "../hooks/useGameState"; + +import { Header, InfoPopUp, Game, Footer } from "../components"; + +import * as Styled from "../app.styled"; + +export function UnlimitedPage() { + const [solution, setSolution] = React.useState<Song | null>(null); + + const firstRun = localStorage.getItem("firstRun") === null; + + function fetchNewSong() { + setSolution(null); + getSelectSolution().then((s) => setSolution(s)); + } + + React.useEffect(() => { + fetchNewSong(); + }, []); + + const { + guesses, + currentTry, + setSelectedSong, + didGuess, + skip, + guess, + reset, + } = useGameState({ solution, persist: false }); + + const playAgain = React.useCallback(() => { + reset(); + fetchNewSong(); + }, [reset]); + + const [isInfoPopUpOpen, setIsInfoPopUpOpen] = + React.useState<boolean>(firstRun); + + const openInfoPopUp = React.useCallback(() => { + setIsInfoPopUpOpen(true); + }, []); + + const closeInfoPopUp = React.useCallback(() => { + if (firstRun) { + localStorage.setItem("firstRun", "false"); + } + setIsInfoPopUpOpen(false); + }, [localStorage.getItem("firstRun")]); + + if (solution === null) { + return null; + } + + return ( + <main> + <Header openInfoPopUp={openInfoPopUp} /> + {isInfoPopUpOpen && <InfoPopUp onClose={closeInfoPopUp} />} + <Styled.Container> + <Game + guesses={guesses} + didGuess={didGuess} + todaysSolution={solution} + currentTry={currentTry} + setSelectedSong={setSelectedSong} + skip={skip} + guess={guess} + mode="unlimited" + onPlayAgain={playAgain} + /> + </Styled.Container> + <Footer /> + </main> + ); +} |
