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

77 lines
2.2 KiB
JavaScript
Raw Normal View History

import React from 'react'
import PropTypes from 'prop-types'
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-05-02 07:25:55 +01:00
import ScrollableList from './scrollable_list'
2020-04-17 06:35:46 +01:00
import Text from './text'
2020-05-09 03:17:19 +01:00
import Dummy from './dummy'
2020-03-11 23:56:18 +00:00
class CommentList extends ImmutablePureComponent {
2020-05-02 07:25:55 +01:00
2020-03-11 23:56:18 +00:00
render() {
2020-04-17 06:35:46 +01:00
const {
descendants,
commentsLimited,
2020-05-05 06:16:01 +01:00
onViewComments,
ancestorAccountId
2020-04-17 06:35:46 +01:00
} = this.props
const size = descendants.size
2020-05-04 19:44:37 +01:00
const upperLimit = commentsLimited ? 6 : size
2020-05-02 07:25:55 +01:00
const max = Math.min(commentsLimited ? 2 : upperLimit, size)
2020-05-09 03:17:19 +01:00
const Wrapper = !commentsLimited ? ScrollableList : Dummy
2020-03-11 23:56:18 +00:00
return (
<React.Fragment>
2020-05-02 07:25:55 +01: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 06:16:01 +01:00
ancestorAccountId={ancestorAccountId}
2020-05-02 07:25:55 +01:00
indent={descendant.get('indent')}
2020-05-05 06:16:01 +01:00
isHighlighted={descendant.get('isHighlighted')}
2020-05-02 07:25:55 +01:00
/>
))
}
</Wrapper>
2020-04-08 02:06:59 +01:00
{
2020-05-02 07:25:55 +01:00
size > 0 && size > max && commentsLimited &&
<div className={[_s.d, _s.flexRow, _s.px15, _s.pb5, _s.mb10, _s.aiCenter].join(' ')}>
2020-04-17 06:35:46 +01:00
<Button
2020-04-23 07:13:29 +01:00
isText
2020-04-17 06:35:46 +01:00
backgroundColor='none'
color='tertiary'
2020-05-04 19:44:37 +01:00
onClick={onViewComments}
2020-04-17 06:35:46 +01:00
>
<Text weight='bold' color='inherit'>
View more comments
</Text>
</Button>
<div className={[_s.d, _s.mlAuto].join(' ')}>
2020-04-17 06:35:46 +01:00
<Text color='tertiary'>
{max}
&nbsp;of&nbsp;
{size}
</Text>
</div>
</div>
}
</React.Fragment>
2020-03-11 23:56:18 +00:00
)
}
}
CommentList.propTypes = {
commentsLimited: PropTypes.bool,
descendants: ImmutablePropTypes.list,
onViewComments: PropTypes.func.isRequired,
ancestorAccountId: PropTypes.string.isRequired,
}
export default CommentList