fix: add missing ebay parts visibility helper module
This commit is contained in:
parent
23f1ed6297
commit
5d3ee2c4d7
1 changed files with 43 additions and 0 deletions
43
lib/ebay-parts-visibility.ts
Normal file
43
lib/ebay-parts-visibility.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
import type { EbayCacheState } from "@/lib/ebay-parts-match"
|
||||||
|
|
||||||
|
type PartLike = {
|
||||||
|
ebayListings?: Array<unknown>
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue