43 lines
818 B
TypeScript
43 lines
818 B
TypeScript
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
|
|
}
|