11import type { FECollection } from '../frontend/feFront' ;
22import {
3+ brandingEqual ,
34 decideCollectionBranding ,
4- isPaidContentSameBranding ,
5+ shouldStripBrandingFromCards ,
56} from '../lib/branding' ;
67import type { EditionId } from '../lib/edition' ;
78import type { Branding } from '../types/branding' ;
@@ -77,11 +78,16 @@ export const enhanceCollections = ({
7778 const indexToShowFrontBranding =
7879 findCollectionSuitableForFrontBranding ( collections ) ;
7980
81+ // Track the branding from the first primary container to detect duplicates in subsequent primary containers
82+ let firstContainerBranding : Branding | undefined ;
83+
8084 return collections . filter ( isSupported ) . map ( ( collection , index ) => {
8185 const { id, displayName, collectionType, hasMore, href, description } =
8286 collection ;
8387 const allCards = [ ...collection . curated , ...collection . backfill ] ;
84- const collectionBranding = decideCollectionBranding ( {
88+
89+ // First, get the raw collection branding without considering previous containers
90+ const rawCollectionBranding = decideCollectionBranding ( {
8591 frontBranding,
8692 couldDisplayFrontBranding : index === indexToShowFrontBranding ,
8793 cards : allCards ,
@@ -91,8 +97,34 @@ export const enhanceCollections = ({
9197 ( { type } ) => type === 'Branded' ,
9298 ) ?? false ,
9399 } ) ;
94- const stripBrandingFromCards =
95- isPaidContentSameBranding ( collectionBranding ) ;
100+
101+ // Determine if we should hide collection branding due to a previous container
102+ const shouldHideCollectionBranding =
103+ ! ! firstContainerBranding &&
104+ ! ! rawCollectionBranding ?. branding &&
105+ brandingEqual (
106+ firstContainerBranding ,
107+ rawCollectionBranding . branding ,
108+ ) ;
109+
110+ // The actual collection branding to display (hide if duplicate branding of previous container)
111+ const collectionBranding = shouldHideCollectionBranding
112+ ? undefined
113+ : rawCollectionBranding ;
114+
115+ // Store the branding from the first container
116+ if ( ! firstContainerBranding && rawCollectionBranding ) {
117+ firstContainerBranding = rawCollectionBranding . branding ;
118+ }
119+
120+ /** Determine if we should strip branding from cards
121+ * We need to check this directly in here because decideCollectionBranding might return undefined
122+ * when cards have same branding as frontBranding, but we still need to strip in that case
123+ */
124+ const stripBrandingFromCards = shouldStripBrandingFromCards (
125+ rawCollectionBranding ?? allCards ,
126+ editionId ,
127+ ) ;
96128
97129 const containerPalette = decideContainerPalette (
98130 collection . config . metadata ?. map ( ( meta ) => meta . type ) ,
0 commit comments