Some checks failed
Build and Deploy / build-and-deploy (push) Failing after 2m33s
Continues the pattern of eliminating Python sx_call tree-building in favour of data-driven .sx defcomps. POST/PUT/DELETE routes now pass plain data (dicts, lists, scalars) and let .sx handle iteration, conditionals, and layout via map/let/when/if. Single response components wrap OOB swaps. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
60 lines
3.8 KiB
Plaintext
60 lines
3.8 KiB
Plaintext
;; Market cart components
|
|
|
|
(defcomp ~market-cart-add-empty (&key cart-id action csrf)
|
|
(div :id cart-id
|
|
(form :action action :method "post" :sx-post action :sx-target "#cart-mini" :sx-swap "outerHTML" :class "rounded flex items-center"
|
|
(input :type "hidden" :name "csrf_token" :value csrf)
|
|
(input :type "hidden" :name "count" :value "1")
|
|
(button :type "submit" :class "relative inline-flex items-center justify-center text-sm font-medium text-stone-500 hover:bg-emerald-50"
|
|
(span :class "relative inline-flex items-center justify-center"
|
|
(i :class "fa fa-cart-plus text-4xl" :aria-hidden "true"))))))
|
|
|
|
(defcomp ~market-cart-add-quantity (&key cart-id action csrf minus-val plus-val quantity cart-href)
|
|
(div :id cart-id
|
|
(div :class "rounded flex items-center gap-2"
|
|
(form :action action :method "post" :sx-post action :sx-target "#cart-mini" :sx-swap "outerHTML"
|
|
(input :type "hidden" :name "csrf_token" :value csrf)
|
|
(input :type "hidden" :name "count" :value minus-val)
|
|
(button :type "submit" :class "inline-flex items-center justify-center w-8 h-8 text-sm font-medium rounded-full border border-emerald-600 text-emerald-700 hover:bg-emerald-50 text-xl" "-"))
|
|
(a :class "relative inline-flex items-center justify-center text-emerald-700" :href cart-href
|
|
(span :class "relative inline-flex items-center justify-center"
|
|
(i :class "fa-solid fa-shopping-cart text-2xl" :aria-hidden "true")
|
|
(span :class "absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 pointer-events-none"
|
|
(span :class "flex items-center justify-center bg-black text-white rounded-full w-4 h-4 text-xs font-bold" quantity))))
|
|
(form :action action :method "post" :sx-post action :sx-target "#cart-mini" :sx-swap "outerHTML"
|
|
(input :type "hidden" :name "csrf_token" :value csrf)
|
|
(input :type "hidden" :name "count" :value plus-val)
|
|
(button :type "submit" :class "inline-flex items-center justify-center w-8 h-8 text-sm font-medium rounded-full border border-emerald-600 text-emerald-700 hover:bg-emerald-50 text-xl" "+")))))
|
|
|
|
(defcomp ~market-cart-mini-count (&key href count)
|
|
(div :id "cart-mini" :sx-swap-oob "outerHTML"
|
|
(a :href href :class "relative inline-flex items-center justify-center"
|
|
(span :class "relative inline-flex items-center justify-center"
|
|
(i :class "fa-solid fa-shopping-cart text-xl" :aria-hidden "true")
|
|
(span :class "absolute -top-1.5 -right-2 pointer-events-none"
|
|
(span :class "flex items-center justify-center bg-emerald-500 text-white rounded-full min-w-[1.25rem] h-5 text-xs font-bold px-1"
|
|
count))))))
|
|
|
|
(defcomp ~market-cart-mini-empty (&key href logo)
|
|
(div :id "cart-mini" :sx-swap-oob "outerHTML"
|
|
(a :href href :class "relative inline-flex items-center justify-center"
|
|
(img :src logo :class "h-8 w-8 rounded-full object-cover border border-stone-300" :alt ""))))
|
|
|
|
(defcomp ~market-cart-add-oob (&key id content inner)
|
|
(div :id id :sx-swap-oob "outerHTML"
|
|
(if content content (when inner inner))))
|
|
|
|
;; Cart added response — composes cart mini + add/remove OOB in sx
|
|
(defcomp ~market-cart-added-response (&key has-count cart-href blog-href logo
|
|
slug action csrf quantity minus-val plus-val)
|
|
(<>
|
|
(if has-count
|
|
(~market-cart-mini-count :href cart-href :count (str has-count))
|
|
(~market-cart-mini-empty :href blog-href :logo logo))
|
|
(~market-cart-add-oob :id (str "cart-add-" slug)
|
|
:inner (if (= (or quantity "0") "0")
|
|
(~market-cart-add-empty :cart-id (str "cart-" slug) :action action :csrf csrf)
|
|
(~market-cart-add-quantity :cart-id (str "cart-" slug) :action action :csrf csrf
|
|
:minus-val minus-val :plus-val plus-val
|
|
:quantity quantity :cart-href cart-href)))))
|