Skip to content

Commit e199983

Browse files
committed
Implement horizontal list
1 parent bae56f8 commit e199983

File tree

4 files changed

+109
-2
lines changed

4 files changed

+109
-2
lines changed

src/components/common/TagItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const tagStyle = css`
3434
${media.small} {
3535
height: 1.5rem;
3636
font-size: 0.75rem;
37-
border-radius: 0.625rem;
37+
border-radius: 0.75rem;
3838
padding-left: 0.75rem;
3939
padding-right: 0.75rem;
4040
margin-right: 0.5rem;
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import React from 'react';
2+
import styled, { css } from 'styled-components';
3+
import media from '../../lib/styles/media';
4+
import { Tag } from '../../lib/graphql/tags';
5+
import palette from '../../lib/styles/palette';
6+
import { Link } from 'react-router-dom';
7+
import { escapeForUrl } from '../../lib/utils';
8+
9+
export type UserTagHorizontalListProps = {
10+
active: string | null;
11+
tags: Tag[];
12+
postsCount: number;
13+
username: string;
14+
};
15+
16+
function UserTagHorizontalList({
17+
active,
18+
tags,
19+
postsCount,
20+
username,
21+
}: UserTagHorizontalListProps) {
22+
return (
23+
<Block>
24+
<TagItem to={`/@${username}`} active={active === null}>
25+
전체보기 <span>({postsCount})</span>
26+
</TagItem>
27+
{tags.map(tag => (
28+
<TagItem
29+
active={active === escapeForUrl(tag.name)}
30+
key={tag.id}
31+
to={`@${username}?tag=${escapeForUrl(tag.name)}`}
32+
>
33+
{tag.name}
34+
<span>({tag.posts_count})</span>
35+
</TagItem>
36+
))}
37+
</Block>
38+
);
39+
}
40+
41+
const Block = styled.div`
42+
display: none;
43+
${media.large} {
44+
display: flex;
45+
}
46+
overflow-x: auto;
47+
margin-top: -1.5rem;
48+
padding-top: 1rem;
49+
padding-bottom: 1rem;
50+
51+
${media.small} {
52+
padding-left: 1rem;
53+
padding-right: 1rem;
54+
}
55+
margin-bottom: 0.5rem;
56+
`;
57+
58+
const TagItem = styled(Link)<{ active?: boolean }>`
59+
flex-shrink: 0;
60+
height: 1.5rem;
61+
font-size: 0.75rem;
62+
border-radius: 0.75rem;
63+
padding-left: 0.75rem;
64+
padding-right: 0.75rem;
65+
background: ${palette.gray1};
66+
color: ${palette.gray8};
67+
display: flex;
68+
align-items: center;
69+
line-height: 1.5;
70+
71+
span {
72+
margin-left: 0.25rem;
73+
color: ${palette.gray6};
74+
font-size: 0.75rem;
75+
}
76+
77+
${props =>
78+
props.active &&
79+
css`
80+
background: ${palette.teal6};
81+
color: white;
82+
span {
83+
color: white;
84+
opacity: 0.8;
85+
}
86+
`}
87+
88+
text-decoration: none;
89+
90+
& + & {
91+
margin-left: 0.5rem;
92+
}
93+
`;
94+
95+
export default UserTagHorizontalList;

src/components/velog/UserTags.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22

33
import UserTagVerticalList from './UserTagVerticalList';
44
import useUserTags from './hooks/useUserTags';
5+
import UserTagHorizontalList from './UserTagHorizontalList';
56

67
export type UserTagsProps = {
78
username: string;
@@ -20,6 +21,12 @@ function UserTags({ username, tag }: UserTagsProps) {
2021
postsCount={data.postsCount}
2122
username={username}
2223
/>
24+
<UserTagHorizontalList
25+
active={tag}
26+
tags={data.tags}
27+
postsCount={data.postsCount}
28+
username={username}
29+
/>
2330
</>
2431
);
2532
}

src/pages/velog/tabs/UserPostsTab.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import usePreserveScroll from '../../../lib/hooks/usePreserveScroll';
1010
import { Helmet } from 'react-helmet-async';
1111
import { usePrevious } from 'react-use';
1212
import UserTags from '../../../components/velog/UserTags';
13+
import { getScrollTop } from '../../../lib/utils';
1314

1415
export interface UserPostsTabProps
1516
extends RouteComponentProps<{ username: string }> {
@@ -36,7 +37,11 @@ const UserPostsTab: React.FC<UserPostsTabProps> = ({
3637

3738
const prevTag = usePrevious(tag);
3839
useEffect(() => {
39-
if (prevTag !== tag) {
40+
if (
41+
prevTag !== tag &&
42+
window.screen.width > 768 &&
43+
getScrollTop() > window.screen.height * 0.6
44+
) {
4045
window.scrollTo(0, 0);
4146
}
4247
}, [prevTag, tag]);

0 commit comments

Comments
 (0)