SxExpr is now a str subclass so it works everywhere a plain string does (join, isinstance, f-strings) while serialize() still emits it unquoted. sx_call() and all internal render functions (_render_to_sx, async_eval_to_sx, etc.) return SxExpr, eliminating the "forgot to wrap" bug class that caused the sx_content leak and list serialization bugs. - Phase 0: SxExpr(str) with .source property, __add__/__radd__ - Phase 1: sx_call returns SxExpr (drop-in, all 200+ sites unchanged) - Phase 2: async_eval_to_sx, async_eval_slot_to_sx, _render_to_sx, mobile_menu_sx return SxExpr; remove isinstance(str) workaround - Phase 3: Remove ~150 redundant SxExpr() wrappings across 45 files - Phase 4: serialize() docstring, handler return docs, ;; returns: sx Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
82 lines
3.6 KiB
Plaintext
82 lines
3.6 KiB
Plaintext
;; Blog nav-tree fragment handler
|
|
;; returns: sx
|
|
;;
|
|
;; Renders the full scrollable navigation menu bar with app icons.
|
|
;; Uses nav-tree I/O primitive to fetch menu nodes from the blog DB.
|
|
|
|
(defhandler nav-tree (&key app_name path)
|
|
(let ((app (or app_name ""))
|
|
(cur-path (or path "/"))
|
|
(first-seg (first (filter (fn (s) (not (empty? s)))
|
|
(split (trim cur-path) "/"))))
|
|
(items (nav-tree))
|
|
(nav-cls "whitespace-nowrap flex items-center gap-2 rounded p-2 text-sm")
|
|
|
|
;; App slug → URL mapping
|
|
(app-slugs (dict
|
|
:cart (app-url "cart" "/")
|
|
:market (app-url "market" "/")
|
|
:events (app-url "events" "/")
|
|
:federation (app-url "federation" "/")
|
|
:account (app-url "account" "/")
|
|
:artdag (app-url "artdag" "/"))))
|
|
|
|
(let ((item-sxs
|
|
(<>
|
|
;; Nav items from DB
|
|
(map (fn (item)
|
|
(let ((item-slug (or (get item "slug") ""))
|
|
(href (or (get app-slugs item-slug)
|
|
(app-url "blog" (str "/" item-slug "/"))))
|
|
(selected (or (= item-slug (or first-seg ""))
|
|
(= item-slug app))))
|
|
(~blog-nav-item-link
|
|
:href href
|
|
:hx-get href
|
|
:selected (if selected "true" "false")
|
|
:nav-cls nav-cls
|
|
:img (~img-or-placeholder
|
|
:src (get item "feature_image")
|
|
:alt (or (get item "label") item-slug)
|
|
:size-cls "w-8 h-8 rounded-full object-cover flex-shrink-0")
|
|
:label (or (get item "label") item-slug)))) items)
|
|
|
|
;; Hardcoded artdag link
|
|
(~blog-nav-item-link
|
|
:href (app-url "artdag" "/")
|
|
:hx-get (app-url "artdag" "/")
|
|
:selected (if (or (= "artdag" (or first-seg ""))
|
|
(= "artdag" app)) "true" "false")
|
|
:nav-cls nav-cls
|
|
:img (~img-or-placeholder
|
|
:src nil :alt "art-dag"
|
|
:size-cls "w-8 h-8 rounded-full object-cover flex-shrink-0")
|
|
:label "art-dag")))
|
|
|
|
;; Scroll wrapper IDs + hyperscript
|
|
(arrow-cls "scrolling-menu-arrow-menu-items-container")
|
|
(cid "menu-items-container")
|
|
(left-hs (str "on click set #" cid ".scrollLeft to #" cid ".scrollLeft - 200"))
|
|
(scroll-hs (str "on scroll "
|
|
"set cls to '" arrow-cls "' "
|
|
"set arrows to document.getElementsByClassName(cls) "
|
|
"set show to (window.innerWidth >= 640 and "
|
|
"my.scrollWidth > my.clientWidth) "
|
|
"repeat for arrow in arrows "
|
|
"if show remove .hidden from arrow add .flex to arrow "
|
|
"else add .hidden to arrow remove .flex from arrow end "
|
|
"end"))
|
|
(right-hs (str "on click set #" cid ".scrollLeft to #" cid ".scrollLeft + 200")))
|
|
|
|
(if (empty? items)
|
|
(~blog-nav-empty :wrapper-id "menu-items-nav-wrapper")
|
|
(~scroll-nav-wrapper
|
|
:wrapper-id "menu-items-nav-wrapper"
|
|
:container-id cid
|
|
:arrow-cls arrow-cls
|
|
:left-hs left-hs
|
|
:scroll-hs scroll-hs
|
|
:right-hs right-hs
|
|
:items item-sxs
|
|
:oob true)))))
|