Skip to content

Fix/follow #472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/common/FollowButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { gql } from 'apollo-boost';
import useUser from '../../lib/hooks/useUser';
import { toast } from 'react-toastify';
import { themedPalette } from '../../lib/styles/themes';
import palette from '../../lib/styles/palette';

export interface PostFollowButtonProps {
followingUserId: string;
Expand Down Expand Up @@ -84,6 +83,7 @@ const FollowButton: React.FC<PostFollowButtonProps> = ({
__typename: 'User',
},
});

follow({ variables });
setButtonText('팔로잉');
}
Expand Down
17 changes: 17 additions & 0 deletions src/components/post/PostBanner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import HorizontalBanner from '../../containers/post/HorizontalBanner';
import PostCustomBanner from './PostCustomBanner';

interface PostBannerProps {
isDisplayAd?: boolean;
customAd: { image: string; url: string } | null;
}

const PostBanner: React.FC<PostBannerProps> = ({ isDisplayAd, customAd }) => {
if (customAd) {
return <PostCustomBanner image={customAd.image} url={customAd.url} />;
}
return <HorizontalBanner isDisplayAd={isDisplayAd} />;
};

export default PostBanner;
42 changes: 42 additions & 0 deletions src/components/post/PostCustomBanner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';
import styled from 'styled-components';
import VelogResponsive from '../velog/VelogResponsive';
import gtag from '../../lib/gtag';
import media from '../../lib/styles/media';

interface PostCustomBannerProps {
image: string;
url: string;
}

const onClick = () => {
gtag('event', 'ads_banner_click');
};

const PostCustomBanner: React.FC<PostCustomBannerProps> = ({ image, url }) => {
return (
<PostCustomBannerBlock onClick={onClick}>
<a href={url}>
<img src={image} alt="post-custom-banner" />
</a>
</PostCustomBannerBlock>
);
};

const PostCustomBannerBlock = styled(VelogResponsive)`
max-width: 100%;
height: auto;
margin-top: 1rem;

${media.small} {
margin-top: 0.5rem;
}

img {
display: block;
width: 100%;
object-fit: contain;
}
`;

export default PostCustomBanner;
26 changes: 23 additions & 3 deletions src/containers/post/PostViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import { useSetShowFooter } from '../../components/velog/VelogPageTemplate';
import HorizontalBanner from './HorizontalBanner';
import gtag from '../../lib/gtag';
import FollowButton from '../../components/common/FollowButton';
import { BANNER_ADS } from '../../lib/graphql/ad';
import PostBanner from '../../components/post/PostBanner';

const UserProfileWrapper = styled(VelogResponsive)`
margin-top: 16rem;
Expand Down Expand Up @@ -105,6 +107,20 @@ const PostViewer: React.FC<PostViewerProps> = ({
const [likePost, { loading: loadingLike }] = useMutation(LIKE_POST);
const [unlikePost, { loading: loadingUnlike }] = useMutation(UNLIKE_POST);
const { showNotFound } = useNotFound();
const { data: ads } = useQuery(BANNER_ADS, {
variables: {
writerUsername: username,
},
});

const customAd = useMemo(() => {
if (!ads) return null;
if (ads.bannerAds.length === 0) return null;
return {
image: ads.bannerAds[0].image,
url: ads.bannerAds[0].url,
};
}, [ads]);

// const userLogo = useSelector((state: RootState) => state.header.userLogo);
// const velogTitle = useMemo(() => {
Expand Down Expand Up @@ -432,7 +448,7 @@ const PostViewer: React.FC<PostViewerProps> = ({
/>
}
/>
{shouldShowBanner ? <HorizontalBanner /> : null}
{shouldShowBanner ? <PostBanner customAd={customAd} /> : null}
<PostContent isMarkdown={post.is_markdown} body={post.body} />
<UserProfileWrapper>
<UserProfile
Expand All @@ -451,8 +467,12 @@ const PostViewer: React.FC<PostViewerProps> = ({
/>
</UserProfileWrapper>
<LinkedPostList linkedPosts={post.linked_posts} />
{shouldShowBanner && isContentLongEnough ? <HorizontalBanner /> : null}
{shouldShowFooterBanner ? <HorizontalBanner isDisplayAd /> : null}
{shouldShowBanner && isContentLongEnough ? (
<PostBanner customAd={customAd} />
) : null}
{shouldShowFooterBanner ? (
<PostBanner isDisplayAd={true} customAd={customAd} />
) : null}
<PostComments
count={post.comments_count}
comments={post.comments}
Expand Down
21 changes: 21 additions & 0 deletions src/lib/graphql/ad.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { gql } from 'apollo-boost';

export type Ad = {
id: string;
title: string;
body: string;
image: string;
url: string;
};

export const BANNER_ADS = gql`
query BannerAds($writerUsername: String!) {
bannerAds(writer_username: $writerUsername) {
id
title
body
url
image
}
}
`;
10 changes: 8 additions & 2 deletions src/lib/graphql/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,19 @@ export const CONFIRM_CHANGE_EMAIL = gql`

export const FOLLOW_USER = gql`
mutation Follow($following_user_id: ID!) {
follow(following_user_id: $following_user_id)
follow(following_user_id: $following_user_id) {
id
is_followed
}
}
`;

export const UNFOLLOW_USER = gql`
mutation Unfollow($following_user_id: ID!) {
unfollow(following_user_id: $following_user_id)
unfollow(following_user_id: $following_user_id) {
id
is_followed
}
}
`;

Expand Down
2 changes: 1 addition & 1 deletion src/pages/velog/UserPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const UserPage: React.FC<UserPageProps> = ({ match, location }) => {
useEffect(() => {
window.location.href = `${process.env
.REACT_APP_CLIENT_V3_HOST!}/@${username}/posts`;
}, []);
}, [username]);

return (
<UserPageBlock>
Expand Down