2020-08-17 15:07:16 -05:00
|
|
|
import React from 'react'
|
2020-08-17 15:59:29 -05:00
|
|
|
import PropTypes from 'prop-types'
|
2020-03-11 19:56:18 -04:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
2020-04-17 01:35:46 -04:00
|
|
|
import Button from './button'
|
2020-04-07 21:06:59 -04:00
|
|
|
import Comment from './comment'
|
2020-05-02 02:25:55 -04:00
|
|
|
import ScrollableList from './scrollable_list'
|
2020-04-17 01:35:46 -04:00
|
|
|
import Text from './text'
|
2020-05-08 22:17:19 -04:00
|
|
|
import Dummy from './dummy'
|
2020-03-11 19:56:18 -04:00
|
|
|
|
2020-08-17 19:57:35 -05:00
|
|
|
class CommentList extends ImmutablePureComponent {
|
2020-05-02 02:25:55 -04:00
|
|
|
|
2020-03-11 19:56:18 -04:00
|
|
|
render() {
|
2020-04-17 01:35:46 -04:00
|
|
|
const {
|
|
|
|
descendants,
|
|
|
|
commentsLimited,
|
2020-05-05 01:16:01 -04:00
|
|
|
onViewComments,
|
|
|
|
ancestorAccountId
|
2020-04-17 01:35:46 -04:00
|
|
|
} = this.props
|
|
|
|
|
|
|
|
const size = descendants.size
|
2020-05-04 14:44:37 -04:00
|
|
|
const upperLimit = commentsLimited ? 6 : size
|
2020-05-02 02:25:55 -04:00
|
|
|
const max = Math.min(commentsLimited ? 2 : upperLimit, size)
|
|
|
|
|
2020-05-08 22:17:19 -04:00
|
|
|
const Wrapper = !commentsLimited ? ScrollableList : Dummy
|
2020-03-11 19:56:18 -04:00
|
|
|
|
|
|
|
return (
|
2020-08-17 15:07:16 -05:00
|
|
|
<React.Fragment>
|
2020-05-02 02:25:55 -04:00
|
|
|
<Wrapper scrollKey='comments'>
|
|
|
|
{
|
|
|
|
descendants.slice(0, max).map((descendant, i) => (
|
|
|
|
<Comment
|
|
|
|
key={`comment-${descendant.get('statusId')}-${i}`}
|
|
|
|
id={descendant.get('statusId')}
|
2020-05-05 01:16:01 -04:00
|
|
|
ancestorAccountId={ancestorAccountId}
|
2020-05-02 02:25:55 -04:00
|
|
|
indent={descendant.get('indent')}
|
2020-05-05 01:16:01 -04:00
|
|
|
isHighlighted={descendant.get('isHighlighted')}
|
2020-05-02 02:25:55 -04:00
|
|
|
/>
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</Wrapper>
|
2020-04-07 21:06:59 -04:00
|
|
|
{
|
2020-05-02 02:25:55 -04:00
|
|
|
size > 0 && size > max && commentsLimited &&
|
2020-08-18 15:49:11 -05:00
|
|
|
<div className={[_s.d, _s.flexRow, _s.px15, _s.pb5, _s.mb10, _s.aiCenter].join(' ')}>
|
2020-04-17 01:35:46 -04:00
|
|
|
<Button
|
2020-04-23 02:13:29 -04:00
|
|
|
isText
|
2020-04-17 01:35:46 -04:00
|
|
|
backgroundColor='none'
|
|
|
|
color='tertiary'
|
2020-05-04 14:44:37 -04:00
|
|
|
onClick={onViewComments}
|
2020-04-17 01:35:46 -04:00
|
|
|
>
|
|
|
|
<Text weight='bold' color='inherit'>
|
|
|
|
View more comments
|
|
|
|
</Text>
|
|
|
|
</Button>
|
2020-08-18 15:49:11 -05:00
|
|
|
<div className={[_s.d, _s.mlAuto].join(' ')}>
|
2020-04-17 01:35:46 -04:00
|
|
|
<Text color='tertiary'>
|
|
|
|
{max}
|
|
|
|
of
|
|
|
|
{size}
|
|
|
|
</Text>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
2020-08-17 15:07:16 -05:00
|
|
|
</React.Fragment>
|
2020-03-11 19:56:18 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-08-17 19:57:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
CommentList.propTypes = {
|
|
|
|
commentsLimited: PropTypes.bool,
|
|
|
|
descendants: ImmutablePropTypes.list,
|
|
|
|
onViewComments: PropTypes.func.isRequired,
|
|
|
|
ancestorAccountId: PropTypes.string.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default CommentList
|