add no-JS progressive enhancement for all shop flows
All checks were successful
deploy / deploy (push) Successful in 1m23s
All checks were successful
deploy / deploy (push) Successful in 1m23s
Every key shop flow now works via plain HTML forms when JS is unavailable. LiveView progressively enhances when JS connects. - PDP: form wraps variant/qty/add-to-cart with action="/cart/add" - Cart page: qty +/- and remove use form POST fallbacks - Cart/search header icons are now links with phx-click enhancement - Collection sort form has GET action + noscript submit button - New /search page with form-based search for no-JS users - CartController gains add/remove/update_item POST actions - CartHook gains update_quantity_form and remove_item_form handlers - Fix flaky analytics tests caused by event table pollution Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -106,6 +106,34 @@ defmodule BerrypodWeb.CartHook do
|
||||
{:halt, socket}
|
||||
end
|
||||
|
||||
defp handle_cart_event(
|
||||
"update_quantity_form",
|
||||
%{"variant_id" => id, "quantity" => qty_str},
|
||||
socket
|
||||
) do
|
||||
quantity = String.to_integer(qty_str)
|
||||
cart = Cart.update_quantity(socket.assigns.raw_cart, id, quantity)
|
||||
new_qty = Cart.get_quantity(cart, id)
|
||||
|
||||
socket =
|
||||
socket
|
||||
|> broadcast_and_update(cart)
|
||||
|> assign(:cart_status, "Quantity updated to #{new_qty}")
|
||||
|
||||
{:halt, socket}
|
||||
end
|
||||
|
||||
defp handle_cart_event("remove_item_form", %{"variant_id" => id}, socket) do
|
||||
cart = Cart.remove_item(socket.assigns.raw_cart, id)
|
||||
|
||||
socket =
|
||||
socket
|
||||
|> broadcast_and_update(cart)
|
||||
|> assign(:cart_status, "Item removed from cart")
|
||||
|
||||
{:halt, socket}
|
||||
end
|
||||
|
||||
defp handle_cart_event(_event, _params, socket), do: {:cont, socket}
|
||||
|
||||
# Shared info handlers
|
||||
|
||||
Reference in New Issue
Block a user