Skip to content

Commit c91fbf3

Browse files
authored
Merge pull request #472 from velopert/fix/follow
Fix/follow
2 parents f97dcce + 862c583 commit c91fbf3

File tree

7 files changed

+113
-7
lines changed

7 files changed

+113
-7
lines changed

src/components/common/FollowButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { gql } from 'apollo-boost';
88
import useUser from '../../lib/hooks/useUser';
99
import { toast } from 'react-toastify';
1010
import { themedPalette } from '../../lib/styles/themes';
11-
import palette from '../../lib/styles/palette';
1211

1312
export interface PostFollowButtonProps {
1413
followingUserId: string;
@@ -84,6 +83,7 @@ const FollowButton: React.FC<PostFollowButtonProps> = ({
8483
__typename: 'User',
8584
},
8685
});
86+
8787
follow({ variables });
8888
setButtonText('팔로잉');
8989
}

src/components/post/PostBanner.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react';
2+
import HorizontalBanner from '../../containers/post/HorizontalBanner';
3+
import PostCustomBanner from './PostCustomBanner';
4+
5+
interface PostBannerProps {
6+
isDisplayAd?: boolean;
7+
customAd: { image: string; url: string } | null;
8+
}
9+
10+
const PostBanner: React.FC<PostBannerProps> = ({ isDisplayAd, customAd }) => {
11+
if (customAd) {
12+
return <PostCustomBanner image={customAd.image} url={customAd.url} />;
13+
}
14+
return <HorizontalBanner isDisplayAd={isDisplayAd} />;
15+
};
16+
17+
export default PostBanner;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from 'react';
2+
import styled from 'styled-components';
3+
import VelogResponsive from '../velog/VelogResponsive';
4+
import gtag from '../../lib/gtag';
5+
import media from '../../lib/styles/media';
6+
7+
interface PostCustomBannerProps {
8+
image: string;
9+
url: string;
10+
}
11+
12+
const onClick = () => {
13+
gtag('event', 'ads_banner_click');
14+
};
15+
16+
const PostCustomBanner: React.FC<PostCustomBannerProps> = ({ image, url }) => {
17+
return (
18+
<PostCustomBannerBlock onClick={onClick}>
19+
<a href={url}>
20+
<img src={image} alt="post-custom-banner" />
21+
</a>
22+
</PostCustomBannerBlock>
23+
);
24+
};
25+
26+
const PostCustomBannerBlock = styled(VelogResponsive)`
27+
max-width: 100%;
28+
height: auto;
29+
margin-top: 1rem;
30+
31+
${media.small} {
32+
margin-top: 0.5rem;
33+
}
34+
35+
img {
36+
display: block;
37+
width: 100%;
38+
object-fit: contain;
39+
}
40+
`;
41+
42+
export default PostCustomBanner;

src/containers/post/PostViewer.tsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ import { useSetShowFooter } from '../../components/velog/VelogPageTemplate';
4545
import HorizontalBanner from './HorizontalBanner';
4646
import gtag from '../../lib/gtag';
4747
import FollowButton from '../../components/common/FollowButton';
48+
import { BANNER_ADS } from '../../lib/graphql/ad';
49+
import PostBanner from '../../components/post/PostBanner';
4850

4951
const UserProfileWrapper = styled(VelogResponsive)`
5052
margin-top: 16rem;
@@ -105,6 +107,20 @@ const PostViewer: React.FC<PostViewerProps> = ({
105107
const [likePost, { loading: loadingLike }] = useMutation(LIKE_POST);
106108
const [unlikePost, { loading: loadingUnlike }] = useMutation(UNLIKE_POST);
107109
const { showNotFound } = useNotFound();
110+
const { data: ads } = useQuery(BANNER_ADS, {
111+
variables: {
112+
writerUsername: username,
113+
},
114+
});
115+
116+
const customAd = useMemo(() => {
117+
if (!ads) return null;
118+
if (ads.bannerAds.length === 0) return null;
119+
return {
120+
image: ads.bannerAds[0].image,
121+
url: ads.bannerAds[0].url,
122+
};
123+
}, [ads]);
108124

109125
// const userLogo = useSelector((state: RootState) => state.header.userLogo);
110126
// const velogTitle = useMemo(() => {
@@ -432,7 +448,7 @@ const PostViewer: React.FC<PostViewerProps> = ({
432448
/>
433449
}
434450
/>
435-
{shouldShowBanner ? <HorizontalBanner /> : null}
451+
{shouldShowBanner ? <PostBanner customAd={customAd} /> : null}
436452
<PostContent isMarkdown={post.is_markdown} body={post.body} />
437453
<UserProfileWrapper>
438454
<UserProfile
@@ -451,8 +467,12 @@ const PostViewer: React.FC<PostViewerProps> = ({
451467
/>
452468
</UserProfileWrapper>
453469
<LinkedPostList linkedPosts={post.linked_posts} />
454-
{shouldShowBanner && isContentLongEnough ? <HorizontalBanner /> : null}
455-
{shouldShowFooterBanner ? <HorizontalBanner isDisplayAd /> : null}
470+
{shouldShowBanner && isContentLongEnough ? (
471+
<PostBanner customAd={customAd} />
472+
) : null}
473+
{shouldShowFooterBanner ? (
474+
<PostBanner isDisplayAd={true} customAd={customAd} />
475+
) : null}
456476
<PostComments
457477
count={post.comments_count}
458478
comments={post.comments}

src/lib/graphql/ad.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { gql } from 'apollo-boost';
2+
3+
export type Ad = {
4+
id: string;
5+
title: string;
6+
body: string;
7+
image: string;
8+
url: string;
9+
};
10+
11+
export const BANNER_ADS = gql`
12+
query BannerAds($writerUsername: String!) {
13+
bannerAds(writer_username: $writerUsername) {
14+
id
15+
title
16+
body
17+
url
18+
image
19+
}
20+
}
21+
`;

src/lib/graphql/user.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,19 @@ export const CONFIRM_CHANGE_EMAIL = gql`
185185

186186
export const FOLLOW_USER = gql`
187187
mutation Follow($following_user_id: ID!) {
188-
follow(following_user_id: $following_user_id)
188+
follow(following_user_id: $following_user_id) {
189+
id
190+
is_followed
191+
}
189192
}
190193
`;
191194

192195
export const UNFOLLOW_USER = gql`
193196
mutation Unfollow($following_user_id: ID!) {
194-
unfollow(following_user_id: $following_user_id)
197+
unfollow(following_user_id: $following_user_id) {
198+
id
199+
is_followed
200+
}
195201
}
196202
`;
197203

src/pages/velog/UserPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const UserPage: React.FC<UserPageProps> = ({ match, location }) => {
2121
useEffect(() => {
2222
window.location.href = `${process.env
2323
.REACT_APP_CLIENT_V3_HOST!}/@${username}/posts`;
24-
}, []);
24+
}, [username]);
2525

2626
return (
2727
<UserPageBlock>

0 commit comments

Comments
 (0)