Skip to content

Commit

Permalink
Remember the state of km/miles toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
sanidhyas3s authored May 31, 2023
1 parent 7fe4ae7 commit 977763e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/components/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ export default function List({ guesses, win, globeRef, practiceMode }: Props) {
const [orderedGuesses, setOrderedGuesses] = useState(
reorderGuesses(guesses, practiceMode)
);
const [miles, setMiles] = useState(false);
const [miles, setMiles] = useState(() => {
const storedMiles = localStorage.getItem("toggleMiles");
return storedMiles ? JSON.parse(storedMiles) : false;
});
const { locale } = useContext(LocaleContext);
const langNameMap: Record<Locale, LanguageName> = {
"pt-BR": "NAME_PT",
Expand All @@ -66,6 +69,10 @@ export default function List({ guesses, win, globeRef, practiceMode }: Props) {
setOrderedGuesses(reorderGuesses(guesses, practiceMode));
}, [guesses, practiceMode]);

useEffect(() => {
localStorage.setItem("toggleMiles", JSON.stringify(miles));
}, [miles]);

function formatKm(m: number, miles: boolean) {
const METERS_PER_MILE = 1609.34;
const BIN = 10;
Expand Down

0 comments on commit 977763e

Please sign in to comment.