|
1 | 1 | // @flow
|
2 |
| -import React, { Component } from 'react'; |
| 2 | +import React, { Component, Fragment } from 'react'; |
3 | 3 | import CommentIcon from 'react-icons/lib/fa/comment';
|
4 | 4 | import HeartIcon from 'react-icons/lib/fa/heart';
|
| 5 | +import { type UserHistoryItem } from 'store/modules/profile'; |
5 | 6 | import './UserHistory.scss';
|
6 | 7 |
|
7 | 8 | type HistoryItemProps = {
|
8 |
| - type: 'comment' | 'like', |
| 9 | + item: UserHistoryItem, |
9 | 10 | };
|
10 | 11 |
|
11 |
| -const HistoryItem = ({ type }: HistoryItemProps) => { |
| 12 | +const HistoryItem = ({ item }: HistoryItemProps) => { |
| 13 | + const { type } = item; |
12 | 14 | return (
|
13 | 15 | <div className="HistoryItem">
|
14 |
| - <div className="message"> |
15 |
| - <CommentIcon className="comment" />@velopert님이 댓글을 남기셨습니다. |
16 |
| - </div> |
17 |
| - <div className="mini-postcard"> |
18 |
| - <div className="thumbnail"> |
19 |
| - <img |
20 |
| - src="https://thumb.velog.io/resize?url=https://images.velog.io/post-images/clarekang/75978a70-c53e-11e8-a8ba-eb98e52ccb66/cucumber.jpg&width=512" |
21 |
| - alt="thumbnail" |
22 |
| - /> |
| 16 | + {type === 'comment' ? ( |
| 17 | + <div className="message"> |
| 18 | + <CommentIcon className="comment" />@velopert님이 댓글을 남기셨습니다. |
23 | 19 | </div>
|
24 |
| - <div className="separator" /> |
| 20 | + ) : ( |
| 21 | + <div className="message"> |
| 22 | + <HeartIcon className="heart" /> |
| 23 | + @velopert님이 이 포스트를 좋아합니다. |
| 24 | + </div> |
| 25 | + )} |
| 26 | + <div className="mini-postcard"> |
| 27 | + {item.post.thumbnail && ( |
| 28 | + <Fragment> |
| 29 | + <div className="thumbnail"> |
| 30 | + <img src={item.post.thumbnail} alt="thumbnail" /> |
| 31 | + </div> |
| 32 | + <div className="separator" /> |
| 33 | + </Fragment> |
| 34 | + )} |
25 | 35 | <div className="post-info">
|
26 |
| - <h4>제목이라능</h4> |
| 36 | + <h4>{item.post.title}</h4> |
27 | 37 | <p>
|
28 |
| - 쇼트 디스립션은 한 100자정도만 보여줄꺼지롱 나는 아무거나 쓸건데 이걸 쓰는 동안에는 |
29 |
| - 오타를 엄청나게 많이 낼 것이다. 왜냐하면 나는 아무 생각없이 쓰고 있기때문이고 지금 사실 |
30 |
| - 눈을 감고있다. 지금 드는 감정에 대해서 묘사를 하자면 음파음파 꼬르르이다. |
| 38 | + {item.post.short_description.slice(0, 150)} |
| 39 | + {item.post.short_description.length >= 150 && '...'} |
31 | 40 | </p>
|
32 | 41 | </div>
|
33 | 42 | </div>
|
34 |
| - <div className="comment-block"> |
35 |
| - <div className="mark">“</div> |
36 |
| - <div className="comment-text"> |
37 |
| - 제 생각엔 제가 댓글을 달았는데 그게 진짜 댓글이 아니더라구요.. ㄷ 근데 문제는 그게 |
38 |
| - 무슨소리인지 모르겠다는거에요. |
| 43 | + {type === 'comment' && ( |
| 44 | + <div className="comment-block"> |
| 45 | + <div className="mark">“</div> |
| 46 | + <div className="comment-text">{item.text}</div> |
39 | 47 | </div>
|
40 |
| - </div> |
| 48 | + )} |
41 | 49 | </div>
|
42 | 50 | );
|
43 | 51 | };
|
44 | 52 |
|
45 |
| -type Props = {}; |
| 53 | +type Props = { |
| 54 | + username: string, |
| 55 | + data: UserHistoryItem[], |
| 56 | +}; |
46 | 57 | class UserHistory extends Component<Props> {
|
| 58 | + renderList() { |
| 59 | + const { username, data } = this.props; |
| 60 | + return data.map(item => <HistoryItem username={username} item={item} key={item.id} />); |
| 61 | + } |
47 | 62 | render() {
|
48 |
| - return ( |
49 |
| - <div className="UserHistory"> |
50 |
| - <HistoryItem type="comment" /> |
51 |
| - <HistoryItem type="comment" /> |
52 |
| - <HistoryItem type="comment" /> |
53 |
| - <HistoryItem type="comment" /> |
54 |
| - <HistoryItem type="like" /> |
55 |
| - </div> |
56 |
| - ); |
| 63 | + return <div className="UserHistory">{this.renderList()}</div>; |
57 | 64 | }
|
58 | 65 | }
|
59 | 66 |
|
|
0 commit comments