|
@@ -1,12 +1,15 @@
|
|
|
import { useState, useCallback, useEffect } from 'react';
|
|
import { useState, useCallback, useEffect } from 'react';
|
|
|
import type { PersistedState } from '@wordle/shared';
|
|
import type { PersistedState } from '@wordle/shared';
|
|
|
import { defaultPersistedState } from '@wordle/shared';
|
|
import { defaultPersistedState } from '@wordle/shared';
|
|
|
|
|
+import { detectLang } from '../messages/index.js';
|
|
|
|
|
|
|
|
-const STORAGE_KEY = 'wordle-state';
|
|
|
|
|
|
|
+function storageKey(): string {
|
|
|
|
|
+ return `wordle-state-${detectLang()}`;
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
function loadState(): PersistedState {
|
|
function loadState(): PersistedState {
|
|
|
try {
|
|
try {
|
|
|
- const raw = localStorage.getItem(STORAGE_KEY);
|
|
|
|
|
|
|
+ const raw = localStorage.getItem(storageKey());
|
|
|
if (raw) {
|
|
if (raw) {
|
|
|
return JSON.parse(raw) as PersistedState;
|
|
return JSON.parse(raw) as PersistedState;
|
|
|
}
|
|
}
|
|
@@ -17,7 +20,7 @@ function loadState(): PersistedState {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function saveState(state: PersistedState): void {
|
|
function saveState(state: PersistedState): void {
|
|
|
- localStorage.setItem(STORAGE_KEY, JSON.stringify(state));
|
|
|
|
|
|
|
+ localStorage.setItem(storageKey(), JSON.stringify(state));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export function usePersistence() {
|
|
export function usePersistence() {
|