From 5d3ee2c4d7a3b8019af8476a080b15ab8df9ba4b Mon Sep 17 00:00:00 2001 From: DMleadgen Date: Thu, 16 Apr 2026 16:18:31 -0600 Subject: [PATCH] fix: add missing ebay parts visibility helper module --- lib/ebay-parts-visibility.ts | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 lib/ebay-parts-visibility.ts diff --git a/lib/ebay-parts-visibility.ts b/lib/ebay-parts-visibility.ts new file mode 100644 index 00000000..551e05c1 --- /dev/null +++ b/lib/ebay-parts-visibility.ts @@ -0,0 +1,43 @@ +import type { EbayCacheState } from "@/lib/ebay-parts-match" + +type PartLike = { + ebayListings?: Array +} + +const HIDDEN_CACHE_STATUSES = new Set([ + "rate_limited", + "missing_config", + "disabled", + "error", +]) + +export function hasTrustedPartsListings(parts: PartLike[]) { + return parts.some((part) => (part.ebayListings || []).length > 0) +} + +export function shouldShowEbayPartsPanel(args: { + isLoading: boolean + parts: PartLike[] + cache: EbayCacheState | null + error: string | null +}) { + if (args.isLoading) { + return true + } + + const hasListings = hasTrustedPartsListings(args.parts) + if (hasListings) { + return true + } + + const status = args.cache?.status || "idle" + if (HIDDEN_CACHE_STATUSES.has(status)) { + return false + } + + if (args.error) { + return false + } + + return false +}