2020-12-16 07:39:07 +00:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
2020-12-21 18:25:05 +00:00
|
|
|
import { me } from '../initial_state'
|
|
|
|
import {
|
2020-12-22 17:11:22 +00:00
|
|
|
fetchAlbums,
|
|
|
|
expandAlbums,
|
2020-12-21 18:25:05 +00:00
|
|
|
} from '../actions/albums'
|
2020-12-16 07:39:07 +00:00
|
|
|
import ColumnIndicator from '../components/column_indicator'
|
2020-12-18 04:46:37 +00:00
|
|
|
import Heading from '../components/heading'
|
|
|
|
import TabBar from '../components/tab_bar'
|
2020-12-16 07:39:07 +00:00
|
|
|
import LoadMore from '../components/load_more'
|
|
|
|
import Block from '../components/block'
|
2020-12-18 04:46:37 +00:00
|
|
|
import Album from '../components/album'
|
2020-12-21 18:25:05 +00:00
|
|
|
import Dummy from '../components/dummy'
|
2020-12-16 07:39:07 +00:00
|
|
|
import MediaGalleryPlaceholder from '../components/placeholder/media_gallery_placeholder'
|
|
|
|
|
|
|
|
class AccountAlbums extends ImmutablePureComponent {
|
|
|
|
|
2020-12-21 18:25:05 +00:00
|
|
|
componentDidMount() {
|
|
|
|
const { accountId, mediaType } = this.props
|
|
|
|
|
|
|
|
if (accountId && accountId !== -1) {
|
|
|
|
this.props.onFetchAccountAlbums(accountId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
if (nextProps.accountId && nextProps.accountId !== this.props.accountId) {
|
|
|
|
this.props.onFetchAccountAlbums(nextProps.accountId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleLoadMore = () => {
|
|
|
|
const { accountId, hasMore } = this.props
|
|
|
|
if (accountId && accountId !== -1 && hasMore) {
|
|
|
|
this.props.onExpandAccountAlbums(accountId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleLoadOlder = (e) => {
|
|
|
|
e.preventDefault()
|
|
|
|
this.handleLoadMore()
|
|
|
|
}
|
2020-12-16 07:39:07 +00:00
|
|
|
|
|
|
|
render() {
|
2020-12-21 00:28:32 +00:00
|
|
|
const {
|
|
|
|
isMe,
|
2020-12-22 17:11:22 +00:00
|
|
|
albumIds,
|
2020-12-21 18:25:05 +00:00
|
|
|
account,
|
|
|
|
accountId,
|
|
|
|
hasMore,
|
|
|
|
isLoading,
|
2020-12-21 00:28:32 +00:00
|
|
|
} = this.props
|
|
|
|
|
|
|
|
if (!account) return null
|
2020-12-22 17:11:22 +00:00
|
|
|
const hasAlbums = !!albumIds ? albumIds.size > 0 : false
|
|
|
|
|
|
|
|
console.log("albumIds:", albumIds)
|
2020-12-21 00:28:32 +00:00
|
|
|
|
2020-12-16 07:39:07 +00:00
|
|
|
return (
|
|
|
|
<Block>
|
2020-12-18 04:46:37 +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'>Photos</Heading>
|
|
|
|
</div>
|
|
|
|
<TabBar tabs={[
|
|
|
|
{
|
|
|
|
title: 'All Photos',
|
2020-12-21 00:28:32 +00:00
|
|
|
to: `/${account.get('username')}/photos`,
|
2020-12-18 04:46:37 +00:00
|
|
|
},
|
2020-12-22 17:11:22 +00:00
|
|
|
// {
|
|
|
|
// title: 'Albums',
|
|
|
|
// isActive: true,
|
|
|
|
// to: `/${account.get('username')}/albums`,
|
|
|
|
// },
|
2020-12-18 04:46:37 +00:00
|
|
|
]}/>
|
2020-12-16 07:39:07 +00:00
|
|
|
</div>
|
|
|
|
|
2020-12-18 04:46:37 +00:00
|
|
|
<div className={[_s.d, _s.w100PC, _s.flexRow, _s.flexWrap, _s.px10, _s.mb15, _s.pb10].join(' ')}>
|
2020-12-21 00:28:32 +00:00
|
|
|
{ isMe && <Album isAddable /> }
|
2020-12-21 18:25:05 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
hasAlbums &&
|
2020-12-22 17:11:22 +00:00
|
|
|
albumIds.map((albumId, i) => (
|
2020-12-21 18:25:05 +00:00
|
|
|
<Album
|
2020-12-22 17:11:22 +00:00
|
|
|
key={albumId}
|
|
|
|
albumId={albumId}
|
2020-12-21 18:25:05 +00:00
|
|
|
account={account}
|
|
|
|
/>
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Array.apply(null, { length: 8}).map((_, i) => (
|
|
|
|
<Dummy className={[_s.d, _s.minW162PX, _s.px5, _s.flex1].join(' ')} />
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
!isLoading && !hasAlbums && me !== accountId &&
|
|
|
|
<ColumnIndicator type='error' message='No albums exist' />
|
|
|
|
}
|
2020-12-18 04:46:37 +00:00
|
|
|
</div>
|
2020-12-21 18:25:05 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
hasMore && !(isLoading && !hasAlbums) &&
|
|
|
|
<LoadMore visible={!isLoading} onClick={this.handleLoadOlder} />
|
|
|
|
}
|
2020-12-16 07:39:07 +00:00
|
|
|
</Block>
|
|
|
|
)
|
2020-12-21 00:28:32 +00:00
|
|
|
|
2020-12-16 07:39:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = (state, { account, mediaType }) => {
|
|
|
|
const accountId = !!account ? account.get('id') : -1
|
|
|
|
|
|
|
|
return {
|
|
|
|
accountId,
|
2020-12-22 17:11:22 +00:00
|
|
|
albumIds: state.getIn(['album_lists', accountId, 'items']),
|
2020-12-21 18:25:05 +00:00
|
|
|
isLoading: state.getIn(['album_lists', accountId, 'isLoading'], false),
|
|
|
|
hasMore: state.getIn(['album_lists', accountId, 'hasMore'], false),
|
2020-12-16 07:39:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
2020-12-21 18:25:05 +00:00
|
|
|
onFetchAccountAlbums(accountId) {
|
2020-12-22 17:11:22 +00:00
|
|
|
dispatch(fetchAlbums(accountId))
|
2020-12-21 18:25:05 +00:00
|
|
|
},
|
|
|
|
onExpandAccountAlbums(accountId) {
|
2020-12-22 17:11:22 +00:00
|
|
|
dispatch(expandAlbums(accountId))
|
2020-12-21 18:25:05 +00:00
|
|
|
},
|
2020-12-16 07:39:07 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
AccountAlbums.propTypes = {
|
|
|
|
account: ImmutablePropTypes.map,
|
|
|
|
accountId: PropTypes.string,
|
2020-12-22 17:11:22 +00:00
|
|
|
albumIds: ImmutablePropTypes.list,
|
2020-12-16 07:39:07 +00:00
|
|
|
isLoading: PropTypes.bool,
|
|
|
|
hasMore: PropTypes.bool,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
}
|
|
|
|
|
2020-12-21 18:25:05 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(AccountAlbums)
|