Skip to content

Commit ec94991

Browse files
committed
Insert ads within feed
1 parent 8dabdb2 commit ec94991

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/components/common/AdFeed.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ function AdFeed() {
1515
data-ad-layout-key="-6u+e7+18-4k+8t"
1616
data-ad-client="ca-pub-5574866530496701"
1717
data-ad-slot="3828701581"
18-
data-adtest="on"
1918
></ins>
2019
</Block>
2120
);

src/components/common/PostCardGrid.tsx

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect } from 'react';
1+
import React, { useState, useEffect, useMemo } from 'react';
22
import styled from 'styled-components';
33
import PostCard, { PostCardSkeleton } from './PostCard';
44
import { PartialPost } from '../../lib/graphql/post';
@@ -12,19 +12,30 @@ export type PostCardGridProps = {
1212
};
1313

1414
function PostCardGrid({ posts, loading, forHome }: PostCardGridProps) {
15-
const [adVisible, setAdVisible] = useState(false);
16-
useEffect(() => {
17-
if (localStorage.getItem('SHOW_AD') === 'true') {
18-
setAdVisible(true);
15+
// const [adVisible, setAdVisible] = useState(true);
16+
// useEffect(() => {
17+
// if (localStorage.getItem('SHOW_AD') === 'true') {
18+
// setAdVisible(true);
19+
// }
20+
// }, []);
21+
22+
const postsWithAds = useMemo(() => {
23+
if (!forHome) return posts;
24+
const cloned: (PartialPost | undefined)[] = [...posts];
25+
cloned.splice(4, 0, undefined);
26+
if (cloned.length > 30) {
27+
cloned.splice(20, 0, undefined);
1928
}
20-
}, []);
29+
return cloned;
30+
}, [posts, forHome]);
2131

2232
return (
2333
<Block>
24-
{adVisible && <AdFeed />}
25-
{posts.map((post) => (
26-
<PostCard post={post} key={post.id} forHome={forHome} />
27-
))}
34+
{postsWithAds.map((post) => {
35+
if (post)
36+
return <PostCard post={post} key={post.id} forHome={forHome} />;
37+
return <AdFeed />;
38+
})}
2839
{loading &&
2940
Array.from({ length: 8 }).map((_, i) => (
3041
<PostCardSkeleton key={i} forHome={forHome} />

0 commit comments

Comments
 (0)