fix: persist UI preferences across navigation and sessions #48

Merged
naomi merged 5 commits from fix/sticky into main 2026-03-09 22:17:13 -07:00
Showing only changes of commit fc93efd245 - Show all commits
@@ -16,6 +16,31 @@ import type { Adventurer } from "@elysium/types";
type BatchSize = 1 | 5 | 10 | 25 | 100 | "max";
const batchOptions: Array<BatchSize> = [ 1, 5, 10, 25, 100, "max" ];
/**
* Parses a localStorage string back into a valid BatchSize, defaulting to 1.
* @param stored - The raw string from localStorage (or null if absent).
* @returns A valid BatchSize value.
*/
const parseBatchSize = (stored: string | null): BatchSize => {
if (stored === "max") {
return "max";
}
const numeric = Number(stored);
if (numeric === 5) {
return 5;
}
if (numeric === 10) {
return 10;
}
if (numeric === 25) {
return 25;
}
if (numeric === 100) {
return 100;
}
return 1;
};
/**
* Computes the total cost to buy a batch of adventurers.
* @param adventurer - The adventurer to buy.
@@ -148,7 +173,9 @@ const AdventurerCard = ({
const AdventurerPanel = (): JSX.Element => {
const { state, formatNumber } = useGame();
const [ showLocked, setShowLocked ] = useState(true);
const [ batchSize, setBatchSize ] = useState<BatchSize>(1);
const [ batchSize, setBatchSize ] = useState<BatchSize>(() => {
return parseBatchSize(localStorage.getItem("elysium_batch_size"));
});
if (state === null) {
return (
@@ -196,6 +223,7 @@ const AdventurerPanel = (): JSX.Element => {
{batchOptions.map((option) => {
function handleBatchSelect(): void {
setBatchSize(option);
localStorage.setItem("elysium_batch_size", String(option));
}
return (
<button