generated from nhcarrigan/template
feat: persist crafting zone selection in sessionStorage (#49)
## Summary - Applies the same sticky-zone pattern from #48 to the crafting panel (`elysium_craft_zone` key in sessionStorage) - Introduces a `handleZoneSelect` wrapper so sessionStorage is updated alongside React state on every zone change - Gracefully falls back to `verdant_vale` if no stored value exists ## Test plan - [x] Lint — zero errors, zero warnings - [x] Build — all packages build cleanly - [ ] Manual: select a non-default zone in the crafting panel, navigate away and back — zone should still be selected - [ ] Manual: log out and back in — zone should reset to Verdant Vale ✨ This PR was created with help from Hikari~ 🌸 Reviewed-on: #49 Co-authored-by: Hikari <hikari@nhcarrigan.com> Co-committed-by: Hikari <hikari@nhcarrigan.com>
This commit was merged in pull request #49.
This commit is contained in:
@@ -26,7 +26,9 @@ const bonusLabel: Record<string, string> = {
|
||||
*/
|
||||
const CraftingPanel = (): JSX.Element => {
|
||||
const { state, craftRecipe, formatNumber } = useGame();
|
||||
const [ activeZoneId, setActiveZoneId ] = useState("verdant_vale");
|
||||
const [ activeZoneId, setActiveZoneId ] = useState(() => {
|
||||
return sessionStorage.getItem("elysium_craft_zone") ?? "verdant_vale";
|
||||
});
|
||||
const [ pendingRecipeId, setPendingRecipeId ] = useState<string | null>(null);
|
||||
|
||||
if (state === null) {
|
||||
@@ -68,6 +70,11 @@ const CraftingPanel = (): JSX.Element => {
|
||||
});
|
||||
}
|
||||
|
||||
function handleZoneSelect(zoneId: string): void {
|
||||
setActiveZoneId(zoneId);
|
||||
sessionStorage.setItem("elysium_craft_zone", zoneId);
|
||||
}
|
||||
|
||||
async function handleCraft(recipeId: string): Promise<void> {
|
||||
setPendingRecipeId(recipeId);
|
||||
try {
|
||||
@@ -85,7 +92,7 @@ const CraftingPanel = (): JSX.Element => {
|
||||
|
||||
<ZoneSelector
|
||||
activeZoneId={activeZoneId}
|
||||
onSelectZone={setActiveZoneId}
|
||||
onSelectZone={handleZoneSelect}
|
||||
zones={zones}
|
||||
/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user