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
|
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Type from 'ba-styles/Typography.scss';
import { withStyles } from '@material-ui/core/styles';
import Send from '@material-ui/icons/Send';
import CommentIcon from '@material-ui/icons/Comment';
import CloseIcon from '@material-ui/icons/Close';
import dummy from 'ba-api/dummyContents';
import {
Typography,
List,
ListItem,
Avatar,
Input,
Dialog,
DialogActions,
DialogContent,
DialogTitle,
IconButton,
Fab,
Slide,
Divider,
withMobileDialog,
} from '@material-ui/core';
import styles from './jss/socialMedia-jss';
const Transition = React.forwardRef(function Transition(props, ref) { // eslint-disable-line
return <Slide direction="up" ref={ref} {...props} />;
});
class Comment extends React.Component {
state = {
comment: ''
};
handleChange = event => {
this.setState({ comment: event.target.value });
};
handleSubmit = comment => {
this.props.submitComment(comment);
this.setState({ comment: '' });
}
render() {
const {
open,
handleClose,
classes,
dataComment,
fullScreen
} = this.props;
const { comment } = this.state;
const getItem = dataArray => dataArray.map(data => (
<Fragment key={data.get('id')}>
<ListItem>
<div className={classes.commentContent}>
<div className={classes.commentHead}>
<Avatar alt="avatar" src={data.get('avatar')} className={classes.avatar} />
<section>
<Typography variant="subtitle1">{data.get('from')}</Typography>
<Typography variant="caption"><span className={classNames(Type.light, Type.textGrey)}>{data.get('date')}</span></Typography>
</section>
</div>
<Typography className={classes.commentText}>{data.get('message')}</Typography>
</div>
</ListItem>
<Divider variant="inset" />
</Fragment>
));
return (
<div>
<Dialog
fullScreen={fullScreen}
open={open}
onClose={handleClose}
aria-labelledby="form-dialog-title"
TransitionComponent={Transition}
maxWidth="md"
>
<DialogTitle id="form-dialog-title">
<CommentIcon />
{' '}
{dataComment !== undefined && dataComment.size}
Comment
{dataComment !== undefined && dataComment.size > 1 ? 's' : ''}
<IconButton onClick={handleClose} className={classes.buttonClose} aria-label="Close">
<CloseIcon />
</IconButton>
</DialogTitle>
<DialogContent>
<List>
{dataComment !== undefined && getItem(dataComment)}
</List>
</DialogContent>
<DialogActions className={classes.commentAction}>
<div className={classes.commentForm}>
<Avatar alt="avatar" src={dummy.user.avatar} className={classes.avatarMini} />
<Input
placeholder="Write Comment"
onChange={this.handleChange}
value={comment}
className={classes.input}
inputProps={{
'aria-label': 'Comment',
}}
/>
<Fab size="small" onClick={() => this.handleSubmit(comment)} color="secondary" aria-label="send" className={classes.button}>
<Send />
</Fab>
</div>
</DialogActions>
</Dialog>
</div>
);
}
}
Comment.propTypes = {
open: PropTypes.bool.isRequired,
handleClose: PropTypes.func.isRequired,
submitComment: PropTypes.func.isRequired,
classes: PropTypes.object.isRequired,
dataComment: PropTypes.object,
fullScreen: PropTypes.bool.isRequired,
};
Comment.defaultProps = {
dataComment: undefined
};
const CommentResponsive = withMobileDialog()(Comment);
export default withStyles(styles)(CommentResponsive);
|