1- import React from 'react'
1+ import React , { useEffect , useState } from 'react'
22import { isDesktop } from 'react-device-detect'
33import { SortableKnob } from 'react-easy-sort'
44import { BsBoxArrowInUpRight } from 'react-icons/bs'
55import { MdOutlineDragIndicator } from 'react-icons/md'
66import { ref } from 'src/config'
7+ import { AdvBanner } from 'src/features/adv'
8+ import { useRemoteConfigStore } from 'src/features/remoteConfig'
79import { useUserPreferences } from 'src/stores/preferences'
810import { SupportedCardType } from 'src/types'
911
1012type CardProps = {
1113 children : React . ReactNode
1214 card : SupportedCardType
15+ withAds ?: boolean
1316 titleComponent ?: React . ReactNode
1417 fullBlock ?: boolean
1518}
1619
17- export const Card = ( { card, titleComponent, children, fullBlock = false } : CardProps ) => {
20+ export const Card = ( {
21+ card,
22+ titleComponent,
23+ withAds = false ,
24+ children,
25+ fullBlock = false ,
26+ } : CardProps ) => {
1827 const { openLinksNewTab } = useUserPreferences ( )
1928 const { link, icon, label, badge } = card
29+ const [ canAdsLoad , setCanAdsLoad ] = useState ( true )
30+ const { adsConfig } = useRemoteConfigStore ( )
31+
32+ useEffect ( ( ) => {
33+ if ( ! adsConfig . enabled || ! withAds ) {
34+ return
35+ }
36+
37+ const handleClassChange = ( ) => {
38+ if ( document . documentElement . classList . contains ( 'dndState' ) ) {
39+ setCanAdsLoad ( false )
40+ } else {
41+ setCanAdsLoad ( true )
42+ }
43+ }
44+
45+ const observer = new MutationObserver ( handleClassChange )
46+ observer . observe ( document . documentElement , { attributes : true } )
47+
48+ return ( ) => {
49+ observer . disconnect ( )
50+ }
51+ } , [ withAds , adsConfig . enabled ] )
52+
2053 const handleHeaderLinkClick = ( e : React . MouseEvent < HTMLAnchorElement > ) => {
2154 e . preventDefault ( )
2255 let url = `${ link } ?${ ref } `
@@ -42,6 +75,8 @@ export const Card = ({ card, titleComponent, children, fullBlock = false }: Card
4275 { badge && < span className = "blockHeaderBadge" > { badge } </ span > }
4376 </ div >
4477
78+ { canAdsLoad && adsConfig . enabled && withAds && < AdvBanner /> }
79+
4580 < div className = "blockContent scrollable" > { children } </ div >
4681 </ div >
4782 )
0 commit comments