Skip to content

Commit e1e60db

Browse files
committed
refactor: IconButton 컴포넌트 사용
1 parent b3c83bd commit e1e60db

3 files changed

Lines changed: 34 additions & 57 deletions

File tree

src/pages/MainPage/PostBody.jsx

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { jsx, css } from '@emotion/react';
33
import { useCallback, useState, useEffect } from 'react';
44
import { useNavigate } from 'react-router-dom';
55
import styled from '@emotion/styled';
6-
import { Image, Text, Icon } from 'components';
6+
import { Image, Text } from 'components';
77
import theme from 'styles/theme';
88
import { setLike, setDisLike } from 'utils/apis/postApi';
99
import { setNotification } from 'utils/apis/userApi';
@@ -12,6 +12,7 @@ import useScrollPosition from 'hooks/useScrollPosition';
1212
import { useUserContext } from 'contexts/UserContext';
1313
import { IMAGE_URLS } from 'utils/constants/images';
1414
import displayedAt from 'utils/functions/displayedAt';
15+
import IconButton from 'components/basic/Icon/IconButton';
1516

1617
const PostBody = ({ index, post, isDetailPage = false }) => {
1718
const { _id: postId, image, likes, comments, createdAt, author } = post || {};
@@ -103,12 +104,18 @@ const PostBody = ({ index, post, isDetailPage = false }) => {
103104
<IconButtons>
104105
<IconButton
105106
name={onHeart ? 'HEART_RED' : 'HEART'} // Todo: 상수화
107+
size={22}
108+
style={IconButtonStyle}
106109
onClick={handleClickHeart}
107110
>
108-
<IconButtonText>{heartCount}</IconButtonText>
111+
<Text fontSize={16} style={IconButtonTextStyle}>
112+
{heartCount}
113+
</Text>
109114
</IconButton>
110-
<IconButton name="COMMENT" onClick={navigateToDetailPage}>
111-
<IconButtonText>{comments.length}</IconButtonText>
115+
<IconButton name="COMMENT" size={22} onClick={navigateToDetailPage}>
116+
<Text fontSize={16} style={IconButtonTextStyle}>
117+
{comments.length}
118+
</Text>
112119
</IconButton>
113120
</IconButtons>
114121
<TextContainer>
@@ -158,38 +165,18 @@ const IconButtons = styled.div`
158165
display: flex;
159166
`;
160167

161-
const IconButton = ({ name, children, onClick }) => {
162-
const style = {
163-
padding: 0,
164-
borderRadius: '0',
165-
marginRight: '16px',
166-
display: 'flex',
167-
alignItems: 'center',
168-
justifyContent: 'center',
169-
backgroundColor: 'transparent',
170-
color: theme.color.fontBlack,
171-
};
172-
return (
173-
<button style={style} onClick={onClick}>
174-
<Icon name={name} size={22} />
175-
{children}
176-
</button>
177-
);
168+
const IconButtonStyle = {
169+
marginRight: '16px',
170+
color: theme.color.fontBlack,
178171
};
179172

180-
const IconButtonText = ({ children, ...props }) => {
181-
const style = {
182-
color: theme.color.fontBlack,
183-
marginLeft: '8px',
184-
PointerEvent: 'none',
185-
lineHeight: '19px',
186-
transform: 'translateY(-1px)',
187-
};
188-
return (
189-
<Text fontSize={16} style={style} {...props}>
190-
{children}
191-
</Text>
192-
);
173+
const IconButtonTextStyle = {
174+
fontSize: '16px',
175+
color: theme.color.fontBlack,
176+
marginLeft: '8px',
177+
PointerEvent: 'none',
178+
lineHeight: '19px',
179+
transform: 'translateY(-1px)',
193180
};
194181

195182
const TextContainer = styled.div`

src/pages/MainPage/PostHeader.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import styled from '@emotion/styled';
22
import { useState, useCallback, useMemo } from 'react';
33
import { useNavigate } from 'react-router-dom';
4-
import IconBtn from './IconButton';
54
import { Profile, Modal } from 'components';
65
import { useUserContext } from 'contexts/UserContext';
76
import theme from 'styles/theme';
8-
import { deletePost } from 'utils/apis/postApi';
97
import useLocalToken from 'hooks/useLocalToken';
10-
import { useEffect } from 'react';
8+
import IconButton from 'components/basic/Icon/IconButton';
119

1210
const PostHeader = ({ post, isDetailPage }) => {
1311
const {
@@ -62,7 +60,7 @@ const PostHeader = ({ post, isDetailPage }) => {
6260
<Profile src={image} userName={fullName} onClick={handleClickProfile} />
6361
{isMyPost && (
6462
<>
65-
<IconBtn name="MORE" size={20} onClick={handleClickMore} />
63+
<IconButton name="MORE" size={20} onClick={handleClickMore} />
6664
<Modal visible={isModal} onClose={onClose}>
6765
<Modal.Custom>
6866
<Buttons>

src/pages/PostDetailPage/index.jsx

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import styled from '@emotion/styled';
22
import PostItem from 'pages/MainPage/PostItem';
33
import { Avatar, Icon, Modal, PageWrapper } from 'components';
4+
import IconButton from 'components/basic/Icon/IconButton';
45
import theme from 'styles/theme';
56
import { useRef, useCallback, useState, useEffect } from 'react';
67
import useLocalToken from 'hooks/useLocalToken';
@@ -116,7 +117,12 @@ const PostDetailPage = () => {
116117
<CommentText>{comment}</CommentText>
117118
</Content>
118119
{_id === currentUser.id && (
119-
<MoreButton onClick={() => handleMoreClick(commentId)} />
120+
<IconButton
121+
name="MORE"
122+
size={20}
123+
style={MoreButtonStyle}
124+
onClick={() => handleMoreClick(commentId)}
125+
/>
120126
)}
121127
</CommentItem>
122128
))
@@ -232,24 +238,10 @@ const CommentText = styled.p`
232238
white-space: pre-wrap;
233239
`;
234240

235-
const MoreButton = ({ onClick, ...props }) => {
236-
const style = {
237-
borderRadius: '0',
238-
backgroundColor: 'transparent',
239-
padding: 0,
240-
display: 'flex',
241-
alignItems: 'center',
242-
justifyContent: 'center',
243-
position: 'absolute',
244-
top: '23px',
245-
right: '0',
246-
};
247-
248-
return (
249-
<button {...props} style={style} onClick={onClick}>
250-
<Icon className="more-button" name="MORE" size={20} />
251-
</button>
252-
);
241+
const MoreButtonStyle = {
242+
position: 'absolute',
243+
top: '23px',
244+
right: '0',
253245
};
254246

255247
const DeleteCommentButton = styled.button`

0 commit comments

Comments
 (0)