Skip to content

Commit 3841b75

Browse files
committed
feat: occasional ad slots between song cards
1 parent 16ee138 commit 3841b75

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

web/src/modules/browse/components/HomePageComponent.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import LoadMoreButton from './client/LoadMoreButton';
1010
import { TimespanButtonGroup } from './client/TimespanButton';
1111
import SongCard from './SongCard';
1212
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';
1417
import {
1518
Carousel,
1619
CarouselContent,
@@ -76,9 +79,13 @@ export const HomePageComponent = () => {
7679
</div>
7780
<div className='h-6' />
7881
<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+
)}
8289
</SongCardGroup>
8390
<div className='flex flex-col w-full justify-between items-center mt-4'>
8491
{hasMore ? (

web/src/modules/browse/components/client/context/RecentSongs.context.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,40 @@ export function RecentSongsProvider({
4545
const [selectedCategory, setSelectedCategory] = useState<string>('');
4646
const [endpoint, setEndpoint] = useState<string>('/song-browser/recent');
4747

48+
const adCount = 1;
49+
const pageSize = 12;
50+
4851
const fetchRecentSongs = useCallback(
4952
async function () {
5053
setLoading(true);
5154

5255
try {
56+
const fetchCount = pageSize - adCount;
57+
5358
const response = await axiosInstance.get<SongPreviewDtoType[]>(
5459
endpoint,
5560
{
5661
params: {
5762
page,
58-
limit: 12, // TODO: fix constants
63+
limit: fetchCount, // TODO: fix constants
5964
order: false,
6065
},
6166
},
6267
);
6368

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+
6476
setRecentSongs((prevSongs) => [
6577
...prevSongs.filter((song) => song !== null),
6678
...response.data,
6779
]);
6880

69-
if (response.data.length < 12) {
81+
if (response.data.length < fetchCount) {
7082
setHasMore(false);
7183
}
7284
} catch (error) {

web/src/modules/shared/components/client/ads/AdSlots.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ const AdTemplate = ({
3838
adSlot,
3939
adFormat = 'auto',
4040
fullWidthResponsive = 'true',
41+
adLayoutKey,
4142
hiddenClassName = 'hidden',
4243
showCloseButton = true,
4344
}: {
4445
className: string;
4546
adSlot: string;
4647
adFormat: string;
4748
fullWidthResponsive: string;
49+
adLayoutKey?: string;
4850
hiddenClassName?: string;
4951
showCloseButton?: boolean;
5052
}) => {
@@ -86,6 +88,7 @@ const AdTemplate = ({
8688
data-ad-client={pubId}
8789
data-ad-slot={adSlot}
8890
data-ad-format={adFormat}
91+
data-ad-layout-key={adLayoutKey}
8992
data-full-width-responsive={fullWidthResponsive}
9093
></ins>
9194
{showCloseButton && <HideAdButton setIsHidden={setIsHidden} />}
@@ -159,3 +162,18 @@ export const MultiplexAdSlot = ({ className }: { className?: string }) => {
159162
/>
160163
);
161164
};
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+
};

0 commit comments

Comments
 (0)