Skip to content

Commit cdb6773

Browse files
committed
Fix mobile recommendation
1 parent 527b90d commit cdb6773

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed

src/containers/post/PostViewer.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,12 @@ const PostViewer: React.FC<PostViewerProps> = ({
367367
/>
368368
</UserProfileWrapper>
369369
<LinkedPostList linkedPosts={post.linked_posts} />
370-
<RelatedPost type="desktop" />
370+
<RelatedPost />
371371
<PostComments
372372
count={post.comments_count}
373373
comments={post.comments}
374374
postId={post.id}
375375
/>
376-
<RelatedPost type="mobile" />
377376
</PostViewerProvider>
378377
);
379378
};

src/containers/post/RelatedPost.tsx

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,19 @@ import VelogResponsive from '../../components/velog/VelogResponsive';
44
import { detectAnyAdblocker } from 'just-detect-adblock';
55
import media from '../../lib/styles/media';
66

7-
type RelatedPostProps = {
8-
type: 'desktop' | 'mobile';
9-
};
10-
function RelatedPost({ type }: RelatedPostProps) {
7+
function RelatedPost() {
8+
const [isMobile, setIsMobile] = useState(false);
119
const [visible, setVisible] = useState(true);
1210
useEffect(() => {
11+
const width = window.innerWidth;
12+
if (width < 768) {
13+
setIsMobile(true);
14+
}
15+
1316
setTimeout(() => {
14-
const width = window.innerWidth;
15-
if (type === 'desktop' && width < 768) {
16-
setVisible(false);
17-
return;
18-
}
19-
if (type === 'mobile' && width >= 768) {
20-
setVisible(false);
21-
return;
22-
}
23-
setTimeout(() => {
24-
(window.adsbygoogle = window.adsbygoogle || []).push({});
25-
}, 500);
17+
(window.adsbygoogle = window.adsbygoogle || []).push({});
2618
}, 250);
27-
}, [type]);
19+
}, []);
2820

2921
useEffect(() => {
3022
detectAnyAdblocker().then((detected: boolean) => {
@@ -39,7 +31,7 @@ function RelatedPost({ type }: RelatedPostProps) {
3931
return (
4032
<Wrapper>
4133
<h4>관심 있을 만한 포스트</h4>
42-
{type === 'desktop' && (
34+
{!isMobile && (
4335
<ins
4436
className="adsbygoogle"
4537
style={{ display: 'block' }}
@@ -51,16 +43,16 @@ function RelatedPost({ type }: RelatedPostProps) {
5143
data-matched-content-columns-num="3"
5244
></ins>
5345
)}
54-
{type === 'mobile' && (
46+
{isMobile && (
5547
<ins
5648
className="adsbygoogle"
5749
style={{ display: 'block' }}
5850
data-ad-format="autorelaxed"
5951
data-ad-client="ca-pub-5574866530496701"
6052
data-ad-slot="4990574169"
6153
data-matched-content-ui-type="image_stacked"
62-
data-matched-content-rows-num="6"
63-
data-matched-content-columns-num="1"
54+
data-matched-content-rows-num="3"
55+
data-matched-content-columns-num="2"
6456
></ins>
6557
)}
6658
</Wrapper>

0 commit comments

Comments
 (0)