File tree Expand file tree Collapse file tree 3 files changed +43
-6
lines changed
shared/components/client/ads Expand file tree Collapse file tree 3 files changed +43
-6
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,10 @@ import LoadMoreButton from './client/LoadMoreButton';
10
10
import { TimespanButtonGroup } from './client/TimespanButton' ;
11
11
import SongCard from './SongCard' ;
12
12
import SongCardGroup from './SongCardGroup' ;
13
- import { InterSectionAdSlot } from '../../shared/components/client/ads/AdSlots' ;
13
+ import {
14
+ InterSectionAdSlot ,
15
+ SongCardAdSlot ,
16
+ } from '../../shared/components/client/ads/AdSlots' ;
14
17
import {
15
18
Carousel ,
16
19
CarouselContent ,
@@ -76,9 +79,13 @@ export const HomePageComponent = () => {
76
79
</ div >
77
80
< div className = 'h-6' />
78
81
< SongCardGroup data-test = 'recent-songs' >
79
- { recentSongs . map ( ( song , i ) => (
80
- < SongCard key = { i } song = { song } />
81
- ) ) }
82
+ { recentSongs . map ( ( song , i ) =>
83
+ song === undefined ? (
84
+ < SongCardAdSlot key = { i } />
85
+ ) : (
86
+ < SongCard key = { i } song = { song } />
87
+ ) ,
88
+ ) }
82
89
</ SongCardGroup >
83
90
< div className = 'flex flex-col w-full justify-between items-center mt-4' >
84
91
{ hasMore ? (
Original file line number Diff line number Diff line change @@ -45,28 +45,40 @@ export function RecentSongsProvider({
45
45
const [ selectedCategory , setSelectedCategory ] = useState < string > ( '' ) ;
46
46
const [ endpoint , setEndpoint ] = useState < string > ( '/song-browser/recent' ) ;
47
47
48
+ const adCount = 1 ;
49
+ const pageSize = 12 ;
50
+
48
51
const fetchRecentSongs = useCallback (
49
52
async function ( ) {
50
53
setLoading ( true ) ;
51
54
52
55
try {
56
+ const fetchCount = pageSize - adCount ;
57
+
53
58
const response = await axiosInstance . get < SongPreviewDtoType [ ] > (
54
59
endpoint ,
55
60
{
56
61
params : {
57
62
page,
58
- limit : 12 , // TODO: fix constants
63
+ limit : fetchCount , // TODO: fix constants
59
64
order : false ,
60
65
} ,
61
66
} ,
62
67
) ;
63
68
69
+ const newSongs : Array < SongPreviewDtoType | undefined > = response . data ;
70
+
71
+ for ( let i = 0 ; i < adCount ; i ++ ) {
72
+ const adPosition = Math . floor ( Math . random ( ) * newSongs . length ) + 1 ;
73
+ newSongs . splice ( adPosition , 0 , undefined ) ;
74
+ }
75
+
64
76
setRecentSongs ( ( prevSongs ) => [
65
77
...prevSongs . filter ( ( song ) => song !== null ) ,
66
78
...response . data ,
67
79
] ) ;
68
80
69
- if ( response . data . length < 12 ) {
81
+ if ( response . data . length < fetchCount ) {
70
82
setHasMore ( false ) ;
71
83
}
72
84
} catch ( error ) {
Original file line number Diff line number Diff line change @@ -38,13 +38,15 @@ const AdTemplate = ({
38
38
adSlot,
39
39
adFormat = 'auto' ,
40
40
fullWidthResponsive = 'true' ,
41
+ adLayoutKey,
41
42
hiddenClassName = 'hidden' ,
42
43
showCloseButton = true ,
43
44
} : {
44
45
className : string ;
45
46
adSlot : string ;
46
47
adFormat : string ;
47
48
fullWidthResponsive : string ;
49
+ adLayoutKey ?: string ;
48
50
hiddenClassName ?: string ;
49
51
showCloseButton ?: boolean ;
50
52
} ) => {
@@ -86,6 +88,7 @@ const AdTemplate = ({
86
88
data-ad-client = { pubId }
87
89
data-ad-slot = { adSlot }
88
90
data-ad-format = { adFormat }
91
+ data-ad-layout-key = { adLayoutKey }
89
92
data-full-width-responsive = { fullWidthResponsive }
90
93
> </ ins >
91
94
{ showCloseButton && < HideAdButton setIsHidden = { setIsHidden } /> }
@@ -159,3 +162,18 @@ export const MultiplexAdSlot = ({ className }: { className?: string }) => {
159
162
/>
160
163
) ;
161
164
} ;
165
+
166
+ export const SongCardAdSlot = ( { className } : { className ?: string } ) => {
167
+ return (
168
+ < AdTemplate
169
+ className = { cn (
170
+ 'relative rounded-xl bg-zinc-800 p-2 my-8 h-full w-full min-w-64 text-sm text-zinc-400' ,
171
+ className ,
172
+ ) }
173
+ adSlot = '1737918264'
174
+ adFormat = 'fluid'
175
+ adLayoutKey = '-7o+ez-1j-38+bu'
176
+ showCloseButton = { false }
177
+ />
178
+ ) ;
179
+ } ;
You can’t perform that action at this time.
0 commit comments