New Day new word
This commit is contained in:
parent
a7c04bf6a6
commit
cfc7f0dc0d
2 changed files with 4 additions and 3 deletions
|
@ -19,7 +19,7 @@ import {
|
||||||
WORD_NOT_FOUND_MESSAGE,
|
WORD_NOT_FOUND_MESSAGE,
|
||||||
CORRECT_WORD_MESSAGE,
|
CORRECT_WORD_MESSAGE,
|
||||||
} from './constants/strings'
|
} 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 { addStatsForCompletedGame, loadStats } from './lib/stats'
|
||||||
import {
|
import {
|
||||||
loadGameStateFromLocalStorage,
|
loadGameStateFromLocalStorage,
|
||||||
|
@ -53,7 +53,7 @@ function App() {
|
||||||
const [successAlert, setSuccessAlert] = useState('')
|
const [successAlert, setSuccessAlert] = useState('')
|
||||||
const [guesses, setGuesses] = useState<string[]>(() => {
|
const [guesses, setGuesses] = useState<string[]>(() => {
|
||||||
const loaded = loadGameStateFromLocalStorage()
|
const loaded = loadGameStateFromLocalStorage()
|
||||||
if (loaded?.solution !== solution) {
|
if (loaded?.solutionIndex !== solutionIndex) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
const gameWasWon = loaded.guesses.includes(solution)
|
const gameWasWon = loaded.guesses.includes(solution)
|
||||||
|
@ -82,7 +82,7 @@ function App() {
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
saveGameStateToLocalStorage({ guesses, solution })
|
saveGameStateToLocalStorage({ guesses, solution, solutionIndex })
|
||||||
}, [guesses])
|
}, [guesses])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -3,6 +3,7 @@ const gameStateKey = 'gameState'
|
||||||
type StoredGameState = {
|
type StoredGameState = {
|
||||||
guesses: string[]
|
guesses: string[]
|
||||||
solution: string
|
solution: string
|
||||||
|
solutionIndex: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export const saveGameStateToLocalStorage = (gameState: StoredGameState) => {
|
export const saveGameStateToLocalStorage = (gameState: StoredGameState) => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue