1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import FavoriteIcon from '@material-ui/icons/Favorite';
import ShareIcon from '@material-ui/icons/Share';
import CommentIcon from '@material-ui/icons/Comment';
import MoreVertIcon from '@material-ui/icons/MoreVert';
import {
Typography,
Card,
Menu,
MenuItem,
CardHeader,
CardMedia,
CardContent,
CardActions,
IconButton,
Icon,
Avatar,
Tooltip,
} from '@material-ui/core';
import Comment from './Comment';
import styles from './jss/timeline-jss';
const optionsOpt = [
'Option 1',
'Option 2',
'Option 3',
];
const ITEM_HEIGHT = 48;
class Timeline extends React.Component {
state = {
anchorElOpt: null,
openComment: false,
};
handleClickOpt = event => {
this.setState({ anchorElOpt: event.currentTarget });
};
handleCloseOpt = () => {
this.setState({ anchorElOpt: null });
};
handleOpenComment = (data) => {
this.props.fetchComment(data);
this.setState({ openComment: true });
};
handleCloseComment = () => {
this.setState({ openComment: false });
};
render() {
const {
classes,
dataTimeline,
onlike,
commentIndex,
submitComment,
} = this.props;
const { anchorElOpt, openComment } = this.state;
const getItem = dataArray => dataArray.map(data => (
<li key={data.get('id')}>
<div className={classes.iconBullet}>
<Tooltip id={'tooltip-icon-' + data.get('id')} title={data.get('time')}>
<Icon className={classes.icon}>
{data.get('icon')}
</Icon>
</Tooltip>
</div>
<Card className={classes.cardSocmed}>
<CardHeader
avatar={
<Avatar alt="avatar" src={data.get('avatar')} className={classes.avatar} />
}
action={(
<IconButton
aria-label="More"
aria-owns={anchorElOpt ? 'long-menu' : null}
aria-haspopup="true"
className={classes.button}
onClick={this.handleClickOpt}
>
<MoreVertIcon />
</IconButton>
)}
title={data.get('name')}
subheader={data.get('date')}
/>
{ data.get('image') !== ''
&& (
<CardMedia
className={classes.media}
image={data.get('image')}
title={data.get('name')}
/>
)
}
<CardContent>
<Typography component="p">
{data.get('content')}
</Typography>
</CardContent>
<CardActions className={classes.actions}>
<IconButton aria-label="Like this" onClick={() => onlike(data)}>
<FavoriteIcon className={data.get('liked') ? classes.liked : ''} />
</IconButton>
<IconButton aria-label="Share">
<ShareIcon />
</IconButton>
<div className={classes.rightIcon}>
<Typography variant="caption" component="span">
{data.get('comments') !== undefined ? data.get('comments').size : 0}
</Typography>
<IconButton aria-label="Comment" onClick={() => this.handleOpenComment(data)}>
<CommentIcon />
</IconButton>
</div>
</CardActions>
</Card>
</li>
));
return (
<Fragment>
<Menu
id="long-menu"
anchorEl={anchorElOpt}
open={Boolean(anchorElOpt)}
onClose={this.handleCloseOpt}
PaperProps={{
style: {
maxHeight: ITEM_HEIGHT * 4.5,
width: 200,
},
}}
>
{optionsOpt.map(option => (
<MenuItem key={option} selected={option === 'Edit Profile'} onClick={this.handleCloseOpt}>
{option}
</MenuItem>
))}
</Menu>
<Comment
open={openComment}
handleClose={this.handleCloseComment}
submitComment={submitComment}
dataComment={dataTimeline.getIn([commentIndex, 'comments'])}
/>
<ul className={classes.timeline}>
{getItem(dataTimeline)}
</ul>
</Fragment>
);
}
}
Timeline.propTypes = {
classes: PropTypes.object.isRequired,
onlike: PropTypes.func,
dataTimeline: PropTypes.object.isRequired,
fetchComment: PropTypes.func,
submitComment: PropTypes.func,
commentIndex: PropTypes.number,
};
Timeline.defaultProps = {
onlike: () => (false),
fetchComment: () => {},
submitComment: () => {},
commentIndex: 0,
};
export default withStyles(styles)(Timeline);
|