Implement progressive enhancement for yeast swapper with state persistence
Some checks failed
CI / update (push) Failing after 9s

- Add server-side form handling for yeast swapping without JavaScript
- Implement toggle-based URL parameter system (y0=1, y1=1) for clean URLs
- Add server action to toggle yeast flags and preserve all URL state
- Update multiplier forms to preserve yeast toggle states across submissions
- Calculate yeast conversions server-side from original recipe data
- Fix {{multiplier}} placeholder replacement to handle non-numeric amounts
- Enable multiple independent yeast swappers with full state preservation
- Maintain perfect progressive enhancement: works with and without JS

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-04 16:08:29 +02:00
parent 75142aa5ee
commit 7bc51e3a0e
4 changed files with 201 additions and 50 deletions

View File

@@ -0,0 +1,29 @@
import { redirect } from '@sveltejs/kit';
export const actions = {
swapYeast: async ({ request, url }) => {
const formData = await request.formData();
const yeastId = parseInt(formData.get('yeastId') as string);
// Build new URL
const newUrl = new URL(url.pathname, url.origin);
// Restore all parameters from the form data (they were submitted as currentParam_*)
for (const [key, value] of formData.entries()) {
if (key.startsWith('currentParam_')) {
const paramName = key.substring('currentParam_'.length);
newUrl.searchParams.set(paramName, value as string);
}
}
// Toggle the yeast flag - if it exists, remove it; if not, add it
const yeastParam = `y${yeastId}`;
if (newUrl.searchParams.has(yeastParam)) {
newUrl.searchParams.delete(yeastParam);
} else {
newUrl.searchParams.set(yeastParam, '1');
}
throw redirect(303, newUrl.toString());
}
};