Gate search behind CompanySettings.searchEnabled; fix two reported bugs

Search icon now gated behind the new backend toggle, same pattern as
wishlistEnabled — off by default.

Fixed: blog category filter bar was invisible — it was wrapped in
<Reveal>, which sits right at/just past the hero's bottom edge, the
exact "already near the initial viewport" position Reveal.tsx's own
comment documents as a whileInView(margin:"-80px") trap (an element
already visible without scrolling can permanently never register as
"entered view", since `once: true` never gets a second chance). Now a
plain div, no scroll-reveal animation needed for a filter bar anyway.

Fixed: wishlist count showing one behind on the Navbar badge —
useWishlist.ts's toggle() broadcast the "refetch me" event immediately
after the optimistic local update, before the POST request was even
sent. Another instance's resulting refetch could race the actual
server-side write, get the pre-toggle list, and then never get told to
refetch again. Broadcast now only fires after the request settles.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Marco
2026-07-30 22:51:37 +00:00
parent 2eda211a29
commit bc40e22910
5 changed files with 59 additions and 13 deletions
+17
View File
@@ -1022,6 +1022,23 @@ export async function getWishlistEnabled(): Promise<boolean> {
return data.docs?.[0]?.wishlistEnabled ?? false;
}
// Same pattern as getWishlistEnabled() — gates the Navbar's search icon
// (SearchOverlay.tsx). Off by default so the feature stays invisible
// until a tenant explicitly wants it.
export async function getSearchEnabled(): Promise<boolean> {
const params = new URLSearchParams({ "where[tenant.slug][equals]": TENANT_SLUG, limit: "1" });
const res = await fetch(`${PAYLOAD_URL}/api/company-settings?${params}`, {
headers: { "x-order-service-secret": process.env.ORDER_SERVICE_SECRET || "" },
next: { revalidate: 60 },
});
if (!res.ok) {
console.error(`getSearchEnabled: Payload returned ${res.status} ${res.statusText}`);
return false;
}
const data: { docs?: { searchEnabled?: boolean }[] } = await res.json();
return data.docs?.[0]?.searchEnabled ?? false;
}
export type SeoSettings = {
defaultTitle: string | null;
titleTemplate: string | null;