|
| 1 | +import React from 'react'; |
1 | 2 | import { StyledText } from '../../../../components/Text/StyledText'; |
2 | 3 | import theme from '../../../../styles/theme'; |
3 | 4 | import { RcvdMessageProps } from '../../dto'; |
4 | 5 | import { FirstMessageLayout, UserImage, UsernameText, MessageBox, Message, TimeWrapper, MessageLayout } from './styles'; |
5 | 6 |
|
6 | | -const RcvdMessage: React.FC<RcvdMessageProps & { onClickProfile: () => void }> = ({ |
7 | | - fromUserName, |
8 | | - profilePictureUrl, |
9 | | - content, |
10 | | - isFirst, |
11 | | - isSenderChanged, |
12 | | - isPrintTime, |
13 | | - formattedTime, |
14 | | - onClickProfile, |
15 | | -}) => { |
16 | | - if (isFirst) { |
17 | | - return ( |
18 | | - <> |
19 | | - {isSenderChanged && <div style={{ margin: '0', padding: '0', height: '1rem' }} />} |
20 | | - <FirstMessageLayout> |
21 | | - <UserImage onClick={onClickProfile} src={profilePictureUrl} alt="프로필 사진" /> |
22 | | - <MessageBox> |
23 | | - <UsernameText onClick={onClickProfile} style={{ cursor: 'pointer' }} color={theme.colors.black}> |
24 | | - {fromUserName} |
25 | | - </UsernameText> |
| 7 | +const RcvdMessage: React.FC<RcvdMessageProps & { onClickProfile: () => void }> = React.memo( |
| 8 | + ({ |
| 9 | + fromUserName, |
| 10 | + profilePictureUrl, |
| 11 | + content, |
| 12 | + isFirst, |
| 13 | + isSenderChanged, |
| 14 | + isPrintTime, |
| 15 | + formattedTime, |
| 16 | + onClickProfile, |
| 17 | + }) => { |
| 18 | + if (isFirst) { |
| 19 | + return ( |
| 20 | + <> |
| 21 | + {isSenderChanged && <div style={{ margin: '0', padding: '0', height: '1rem' }} />} |
| 22 | + <FirstMessageLayout> |
| 23 | + <UserImage onClick={onClickProfile} src={profilePictureUrl} alt="프로필 사진" /> |
| 24 | + <MessageBox> |
| 25 | + <UsernameText onClick={onClickProfile} style={{ cursor: 'pointer' }} color={theme.colors.black}> |
| 26 | + {fromUserName} |
| 27 | + </UsernameText> |
| 28 | + <Message> |
| 29 | + <StyledText $textTheme={{ style: 'body6-regular', lineHeight: 1.1 }} color={theme.colors.black}> |
| 30 | + {content} |
| 31 | + </StyledText> |
| 32 | + </Message> |
| 33 | + </MessageBox> |
| 34 | + {isPrintTime && <TimeWrapper>{formattedTime}</TimeWrapper>} |
| 35 | + </FirstMessageLayout> |
| 36 | + </> |
| 37 | + ); |
| 38 | + } else { |
| 39 | + return ( |
| 40 | + <> |
| 41 | + {isSenderChanged && <div style={{ margin: '0', padding: '0', height: '2.25rem' }} />} |
| 42 | + <MessageLayout> |
26 | 43 | <Message> |
27 | 44 | <StyledText $textTheme={{ style: 'body6-regular', lineHeight: 1.1 }} color={theme.colors.black}> |
28 | 45 | {content} |
29 | 46 | </StyledText> |
30 | 47 | </Message> |
31 | | - </MessageBox> |
32 | | - {isPrintTime && <TimeWrapper>{formattedTime}</TimeWrapper>} |
33 | | - </FirstMessageLayout> |
34 | | - </> |
35 | | - ); |
36 | | - } else { |
37 | | - return ( |
38 | | - <> |
39 | | - {isSenderChanged && <div style={{ margin: '0', padding: '0', height: '2.25rem' }} />} |
40 | | - <MessageLayout> |
41 | | - <Message> |
42 | | - <StyledText $textTheme={{ style: 'body6-regular', lineHeight: 1.1 }} color={theme.colors.black}> |
43 | | - {content} |
44 | | - </StyledText> |
45 | | - </Message> |
46 | | - {isPrintTime && <TimeWrapper>{formattedTime}</TimeWrapper>} |
47 | | - </MessageLayout> |
48 | | - </> |
49 | | - ); |
50 | | - } |
51 | | -}; |
| 48 | + {isPrintTime && <TimeWrapper>{formattedTime}</TimeWrapper>} |
| 49 | + </MessageLayout> |
| 50 | + </> |
| 51 | + ); |
| 52 | + } |
| 53 | + }, |
| 54 | +); |
52 | 55 |
|
53 | 56 | export default RcvdMessage; |
0 commit comments