New Day new word

This commit is contained in:
Christoph Stahl 2022-02-03 16:21:50 +01:00
parent a7c04bf6a6
commit cfc7f0dc0d
2 changed files with 4 additions and 3 deletions

View file

@ -19,7 +19,7 @@ import {
WORD_NOT_FOUND_MESSAGE,
CORRECT_WORD_MESSAGE,
} from './constants/strings'
import { isWordInWordList, isWinningWord, solution } from './lib/words'
import { isWordInWordList, isWinningWord, solution, solutionIndex } from './lib/words'
import { addStatsForCompletedGame, loadStats } from './lib/stats'
import {
loadGameStateFromLocalStorage,
@ -53,7 +53,7 @@ function App() {
const [successAlert, setSuccessAlert] = useState('')
const [guesses, setGuesses] = useState<string[]>(() => {
const loaded = loadGameStateFromLocalStorage()
if (loaded?.solution !== solution) {
if (loaded?.solutionIndex !== solutionIndex) {
return []
}
const gameWasWon = loaded.guesses.includes(solution)
@ -82,7 +82,7 @@ function App() {
}
useEffect(() => {
saveGameStateToLocalStorage({ guesses, solution })
saveGameStateToLocalStorage({ guesses, solution, solutionIndex })
}, [guesses])
useEffect(() => {

View file

@ -3,6 +3,7 @@ const gameStateKey = 'gameState'
type StoredGameState = {
guesses: string[]
solution: string
solutionIndex: number
}
export const saveGameStateToLocalStorage = (gameState: StoredGameState) => {