From e9a59e5f932ab63b49c032da9ce16f7da23abbf4 Mon Sep 17 00:00:00 2001 From: giles Date: Tue, 24 Feb 2026 09:11:50 +0000 Subject: [PATCH] Add cart + auth fragment pre-fetching to blog context Phase 2 of fragment composition: blog_context() now concurrently fetches cart-mini and auth-menu HTML fragments from cart and account apps via fetch_fragments(). Updates shared submodule. Co-Authored-By: Claude Opus 4.6 --- app.py | 19 ++++++++ shared | 2 +- templates/_types/root/header/_header.html | 54 +++++++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 templates/_types/root/header/_header.html diff --git a/app.py b/app.py index e82f8a9..4db09d0 100644 --- a/app.py +++ b/app.py @@ -25,11 +25,13 @@ async def blog_context() -> dict: - menu_items: via shared.services.navigation - cart_count/cart_total: via cart service (shared DB) + - cart_mini_html / auth_menu_html: pre-fetched fragments """ from shared.infrastructure.context import base_context from shared.services.navigation import get_navigation_tree from shared.services.registry import services from shared.infrastructure.cart_identity import current_cart_identity + from shared.infrastructure.fragments import fetch_fragments ctx = await base_context() @@ -43,6 +45,23 @@ async def blog_context() -> dict: ctx["cart_count"] = summary.count + summary.calendar_count + summary.ticket_count ctx["cart_total"] = float(summary.total + summary.calendar_total + summary.ticket_total) + # Pre-fetch cross-app HTML fragments concurrently + user = getattr(g, "user", None) + cart_params = {} + if ident["user_id"] is not None: + cart_params["user_id"] = ident["user_id"] + if ident["session_id"] is not None: + cart_params["session_id"] = ident["session_id"] + + auth_params = {"email": user.email} if user else {} + + cart_mini_html, auth_menu_html = await fetch_fragments([ + ("cart", "cart-mini", cart_params or None), + ("account", "auth-menu", auth_params or None), + ]) + ctx["cart_mini_html"] = cart_mini_html + ctx["auth_menu_html"] = auth_menu_html + return ctx diff --git a/shared b/shared index b882770..2a9dfaa 160000 --- a/shared +++ b/shared @@ -1 +1 @@ -Subproject commit b882770828be7c62bbd047146e03b83511a2397d +Subproject commit 2a9dfaa749be414903b5edf834fbb201e6466498 diff --git a/templates/_types/root/header/_header.html b/templates/_types/root/header/_header.html new file mode 100644 index 0000000..8442236 --- /dev/null +++ b/templates/_types/root/header/_header.html @@ -0,0 +1,54 @@ +{% set select_colours = " + [.hover-capable_&]:hover:bg-yellow-300 + aria-selected:bg-stone-500 aria-selected:text-white + [.hover-capable_&[aria-selected=true]:hover]:bg-orange-500 +"%} +{% import 'macros/links.html' as links %} + +{% macro header_row(oob=False) %} + {% call links.menu_row(id='root-row', oob=oob) %} +
+ {# Cart mini — fetched from cart app as fragment #} + {% if cart_mini_html %} + {{ cart_mini_html | safe }} + {% else %} + {% from '_types/cart/_mini.html' import mini with context %} + {{mini()}} + {% endif %} + + {# Site title #} +
+ {% from 'macros/title.html' import title with context %} + {{ title('flex justify-center md:justify-start')}} +
+ + {# Desktop nav #} + + {% include '_types/root/_hamburger.html' %} +
+ {% endcall %} + {# Mobile user info #} +
+ {# Auth menu mobile — part of auth-menu fragment (id=auth-menu-mobile) #} + {% if not auth_menu_html %} + {% if g.user %} + {% include '_types/root/mobile/_full_user.html' %} + {% else %} + {% include '_types/root/mobile/_sign_in.html' %} + {% endif %} + {% endif %} +
+{% endmacro %}