Skip to content

Commit 95abba1

Browse files
committed
Different position for mobile & desktop
1 parent 4c02daa commit 95abba1

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/containers/post/PostViewer.tsx

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

src/containers/post/RelatedPost.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
import React, { useEffect } from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import styled from 'styled-components';
33
import VelogResponsive from '../../components/velog/VelogResponsive';
44

5-
function RelatedPost() {
5+
type RelatedPostProps = {
6+
type: 'desktop' | 'mobile';
7+
};
8+
function RelatedPost({ type }: RelatedPostProps) {
9+
const [visible, setVisible] = useState(true);
610
useEffect(() => {
11+
const width = window.innerWidth;
12+
if (type === 'desktop' && width < 468) {
13+
setVisible(false);
14+
return;
15+
}
16+
if (type === 'mobile' && width >= 468) {
17+
setVisible(false);
18+
return;
19+
}
720
(window.adsbygoogle = window.adsbygoogle || []).push({});
8-
}, []);
21+
}, [type]);
22+
23+
if (!visible) return null;
924

1025
return (
1126
<Wrapper>

0 commit comments

Comments
 (0)