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' import { me } from '../initial_state' import { fetchAlbums, expandAlbums, } from '../actions/albums' import ColumnIndicator from '../components/column_indicator' import Heading from '../components/heading' import TabBar from '../components/tab_bar' import LoadMore from '../components/load_more' import Block from '../components/block' import Album from '../components/album' import Dummy from '../components/dummy' import MediaGalleryPlaceholder from '../components/placeholder/media_gallery_placeholder' class AccountAlbums extends ImmutablePureComponent { 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() } render() { const { isMe, albumIds, account, accountId, hasMore, isLoading, } = this.props if (!account) return null const hasAlbums = !!albumIds ? albumIds.size > 0 : false console.log("albumIds:", albumIds) return (
Photos
{ isMe && } { hasAlbums && albumIds.map((albumId, i) => ( )) } { Array.apply(null, { length: 8}).map((_, i) => ( )) } { !isLoading && !hasAlbums && me !== accountId && }
{ hasMore && !(isLoading && !hasAlbums) && }
) } } const mapStateToProps = (state, { account, mediaType }) => { const accountId = !!account ? account.get('id') : -1 return { accountId, albumIds: state.getIn(['album_lists', accountId, 'items']), isLoading: state.getIn(['album_lists', accountId, 'isLoading'], false), hasMore: state.getIn(['album_lists', accountId, 'hasMore'], false), } } const mapDispatchToProps = (dispatch) => ({ onFetchAccountAlbums(accountId) { dispatch(fetchAlbums(accountId)) }, onExpandAccountAlbums(accountId) { dispatch(expandAlbums(accountId)) }, }) AccountAlbums.propTypes = { account: ImmutablePropTypes.map, accountId: PropTypes.string, albumIds: ImmutablePropTypes.list, isLoading: PropTypes.bool, hasMore: PropTypes.bool, intl: PropTypes.object.isRequired, } export default connect(mapStateToProps, mapDispatchToProps)(AccountAlbums)