gab-social/app/javascript/gabsocial/components/comment_list.js

61 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-03-11 23:56:18 +00:00
import ImmutablePropTypes from 'react-immutable-proptypes'
import ImmutablePureComponent from 'react-immutable-pure-component'
2020-04-17 06:35:46 +01:00
import Button from './button'
2020-04-08 02:06:59 +01:00
import Comment from './comment'
2020-04-17 06:35:46 +01:00
import Text from './text'
2020-03-11 23:56:18 +00:00
2020-04-08 02:06:59 +01:00
export default class CommentList extends ImmutablePureComponent {
2020-03-11 23:56:18 +00:00
static propTypes = {
2020-04-17 06:35:46 +01:00
commentsLimited: PropTypes.bool,
2020-04-08 02:06:59 +01:00
descendants: ImmutablePropTypes.list,
2020-03-11 23:56:18 +00:00
}
render() {
2020-04-17 06:35:46 +01:00
const {
descendants,
commentsLimited,
} = this.props
const size = descendants.size
const max = Math.min(commentsLimited ? 2 : 6, size)
console.log("max:", size, max)
2020-03-11 23:56:18 +00:00
return (
2020-04-08 02:06:59 +01:00
<div>
{
2020-04-17 06:35:46 +01:00
descendants.slice(0, max).map((descendant, i) => (
2020-04-08 02:06:59 +01:00
<Comment
key={`comment-${descendant.get('statusId')}-${i}`}
id={descendant.get('statusId')}
indent={descendant.get('indent')}
/>
))
}
2020-04-17 06:35:46 +01:00
{
size > 0 && size > max &&
<div className={[_s.default, _s.flexRow, _s.px15, _s.pb5, _s.mb10, _s.alignItemsCenter].join(' ')}>
<Button
text
backgroundColor='none'
color='tertiary'
>
<Text weight='bold' color='inherit'>
View more comments
</Text>
</Button>
<div className={[_s.default, _s.marginLeftAuto].join(' ')}>
<Text color='tertiary'>
{max}
&nbsp;of&nbsp;
{size}
</Text>
</div>
</div>
}
2020-03-11 23:56:18 +00:00
</div>
)
}
}