2020-08-17 21:07:16 +01:00
|
|
|
import React from 'react'
|
2020-08-17 21:59:29 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2020-08-17 21:39:25 +01:00
|
|
|
import { connect } from 'react-redux'
|
2020-03-04 22:26:01 +00:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
|
|
|
import { injectIntl, defineMessages } from 'react-intl'
|
|
|
|
import { expandAccountMediaTimeline } from '../actions/timelines'
|
|
|
|
import { getAccountGallery } from '../selectors'
|
|
|
|
import ColumnIndicator from '../components/column_indicator'
|
|
|
|
import MediaItem from '../components/media_item'
|
2020-12-21 18:25:05 +00:00
|
|
|
import Dummy from '../components/dummy'
|
2020-03-04 22:26:01 +00:00
|
|
|
import LoadMore from '../components/load_more'
|
|
|
|
import Block from '../components/block'
|
2020-12-21 18:25:05 +00:00
|
|
|
import Heading from '../components/heading'
|
|
|
|
import TabBar from '../components/tab_bar'
|
2020-07-29 21:40:47 +01:00
|
|
|
import MediaGalleryPlaceholder from '../components/placeholder/media_gallery_placeholder'
|
2020-03-04 22:26:01 +00:00
|
|
|
|
2020-12-21 18:25:05 +00:00
|
|
|
class AccountVideoGallery extends ImmutablePureComponent {
|
2020-03-04 22:26:01 +00:00
|
|
|
|
|
|
|
componentDidMount() {
|
2020-12-21 18:25:05 +00:00
|
|
|
const { accountId } = this.props
|
2020-03-04 22:26:01 +00:00
|
|
|
|
2020-04-11 23:29:19 +01:00
|
|
|
if (accountId && accountId !== -1) {
|
2020-12-21 18:25:05 +00:00
|
|
|
this.props.dispatch(expandAccountMediaTimeline(accountId, { mediaType: 'video' }))
|
2020-03-04 22:26:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
2020-12-21 18:25:05 +00:00
|
|
|
if (nextProps.accountId && nextProps.accountId !== this.props.accountId) {
|
2020-06-09 00:38:36 +01:00
|
|
|
this.props.dispatch(expandAccountMediaTimeline(nextProps.accountId, {
|
2020-12-21 18:25:05 +00:00
|
|
|
mediaType: 'video',
|
2020-06-09 00:38:36 +01:00
|
|
|
}))
|
2020-03-04 22:26:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleScrollToBottom = () => {
|
|
|
|
if (this.props.hasMore) {
|
|
|
|
this.handleLoadMore(this.props.attachments.size > 0 ? this.props.attachments.last().getIn(['status', 'id']) : undefined)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-09 00:38:36 +01:00
|
|
|
handleScroll = (e) => {
|
2020-03-04 22:26:01 +00:00
|
|
|
const { scrollTop, scrollHeight, clientHeight } = e.target
|
|
|
|
const offset = scrollHeight - scrollTop - clientHeight
|
|
|
|
|
|
|
|
if (150 > offset && !this.props.isLoading) {
|
|
|
|
this.handleScrollToBottom()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-09 00:38:36 +01:00
|
|
|
handleLoadMore = (maxId) => {
|
2020-03-04 22:26:01 +00:00
|
|
|
if (this.props.accountId && this.props.accountId !== -1) {
|
2020-06-09 00:38:36 +01:00
|
|
|
this.props.dispatch(expandAccountMediaTimeline(this.props.accountId, {
|
|
|
|
maxId,
|
2020-12-21 18:25:05 +00:00
|
|
|
mediaType: 'video',
|
2020-06-09 00:38:36 +01:00
|
|
|
}))
|
2020-03-04 22:26:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-09 00:38:36 +01:00
|
|
|
handleLoadOlder = (e) => {
|
2020-03-04 22:26:01 +00:00
|
|
|
e.preventDefault()
|
|
|
|
this.handleScrollToBottom()
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
attachments,
|
|
|
|
isLoading,
|
|
|
|
hasMore,
|
|
|
|
intl,
|
2020-04-08 02:06:59 +01:00
|
|
|
account,
|
2020-03-04 22:26:01 +00:00
|
|
|
} = this.props
|
|
|
|
|
|
|
|
if (!account) return null
|
|
|
|
|
2020-12-21 18:25:05 +00:00
|
|
|
const hasAttachments = !!attachments ? attachments.size > 0 : false
|
|
|
|
|
2020-03-04 22:26:01 +00:00
|
|
|
return (
|
|
|
|
<Block>
|
2020-12-21 18:25:05 +00:00
|
|
|
<div className={[_s.d, _s.px10, _s.py10].join(' ')}>
|
|
|
|
<div className={[_s.d, _s.px5, _s.py5, _s.mb10].join(' ')}>
|
|
|
|
<Heading size='h2'>Videos</Heading>
|
|
|
|
</div>
|
|
|
|
<TabBar tabs={[
|
|
|
|
{
|
|
|
|
title: 'All Videos',
|
|
|
|
to: `/${account.get('username')}/videos`,
|
|
|
|
},
|
|
|
|
]}/>
|
|
|
|
</div>
|
|
|
|
|
2020-03-04 22:26:01 +00:00
|
|
|
<div
|
|
|
|
role='feed'
|
|
|
|
onScroll={this.handleScroll}
|
2020-12-21 18:25:05 +00:00
|
|
|
className={[_s.d, _s.w100PC, _s.flexRow, _s.flexWrap, _s.px10, _s.mb15, _s.pb10].join(' ')}
|
2020-03-04 22:26:01 +00:00
|
|
|
>
|
|
|
|
|
|
|
|
{
|
2020-12-21 18:25:05 +00:00
|
|
|
hasAttachments &&
|
|
|
|
<React.Fragment>
|
|
|
|
{
|
|
|
|
attachments.map((attachment, i) => (
|
|
|
|
<MediaItem
|
|
|
|
key={attachment.get('id')}
|
|
|
|
attachment={attachment}
|
|
|
|
account={account}
|
|
|
|
/>
|
|
|
|
))
|
|
|
|
}
|
|
|
|
{
|
|
|
|
Array.apply(null, { length: 8 }).map((_, i) => (
|
|
|
|
<Dummy className={[_s.d, _s.minW232PX, _s.px5, _s.flex1].join(' ')} />
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</React.Fragment>
|
2020-03-04 22:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2020-12-21 18:25:05 +00:00
|
|
|
isLoading && !hasAttachments &&
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.w100PC].join(' ')}>
|
2020-07-29 21:40:47 +01:00
|
|
|
<MediaGalleryPlaceholder />
|
|
|
|
</div>
|
2020-03-04 22:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2020-12-21 18:25:05 +00:00
|
|
|
!isLoading && !hasAttachments &&
|
2020-04-28 06:33:58 +01:00
|
|
|
<ColumnIndicator type='error' message={intl.formatMessage(messages.none)} />
|
2020-03-04 22:26:01 +00:00
|
|
|
}
|
|
|
|
</div>
|
2020-04-28 06:33:58 +01:00
|
|
|
|
|
|
|
{
|
2020-12-21 18:25:05 +00:00
|
|
|
hasMore && !(isLoading && !hasAttachments) &&
|
2020-04-28 06:33:58 +01:00
|
|
|
<LoadMore visible={!isLoading} onClick={this.handleLoadOlder} />
|
|
|
|
}
|
2020-03-04 22:26:01 +00:00
|
|
|
</Block>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-08-19 01:22:15 +01:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
none: { id: 'account_gallery.none', defaultMessage: 'No media to show.' },
|
|
|
|
})
|
|
|
|
|
2020-12-21 18:25:05 +00:00
|
|
|
const mapStateToProps = (state, { account }) => {
|
2020-08-19 01:22:15 +01:00
|
|
|
const accountId = !!account ? account.get('id') : -1
|
|
|
|
|
|
|
|
return {
|
|
|
|
accountId,
|
2020-12-21 18:25:05 +00:00
|
|
|
attachments: getAccountGallery(state, accountId, 'video'),
|
2020-08-19 01:22:15 +01:00
|
|
|
isLoading: state.getIn(['timelines', `account:${accountId}:media`, 'isLoading']),
|
|
|
|
hasMore: state.getIn(['timelines', `account:${accountId}:media`, 'hasMore']),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-21 18:25:05 +00:00
|
|
|
AccountVideoGallery.propTypes = {
|
2020-08-19 01:22:15 +01:00
|
|
|
dispatch: PropTypes.func.isRequired,
|
|
|
|
account: ImmutablePropTypes.map,
|
|
|
|
accountId: PropTypes.string,
|
|
|
|
attachments: ImmutablePropTypes.list.isRequired,
|
|
|
|
isLoading: PropTypes.bool,
|
|
|
|
hasMore: PropTypes.bool,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
}
|
|
|
|
|
2020-12-21 18:25:05 +00:00
|
|
|
export default injectIntl(connect(mapStateToProps)(AccountVideoGallery))
|