2020-12-16 07:39:07 +00:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2020-12-21 18:25:05 +00:00
|
|
|
import { connect } from 'react-redux'
|
2020-12-16 07:39:07 +00:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
2020-12-21 18:25:05 +00:00
|
|
|
import { openModal } from '../actions/modal'
|
|
|
|
import {
|
|
|
|
CX,
|
|
|
|
MODAL_ALBUM_CREATE,
|
|
|
|
} from '../constants'
|
2020-12-16 07:39:07 +00:00
|
|
|
import Button from './button'
|
|
|
|
import Icon from './icon'
|
|
|
|
import Image from './image'
|
|
|
|
import Text from './text'
|
|
|
|
|
|
|
|
class Album extends React.PureComponent {
|
|
|
|
|
2020-12-21 18:25:05 +00:00
|
|
|
handleOnOpenAlbumCreate = () => {
|
|
|
|
this.props.openAlbumCreate()
|
2020-12-21 00:28:32 +00:00
|
|
|
}
|
|
|
|
|
2020-12-16 07:39:07 +00:00
|
|
|
render() {
|
2020-12-21 00:28:32 +00:00
|
|
|
const {
|
2020-12-22 17:11:22 +00:00
|
|
|
account,
|
2020-12-21 00:28:32 +00:00
|
|
|
album,
|
|
|
|
isAddable,
|
|
|
|
} = this.props
|
2020-12-22 17:11:22 +00:00
|
|
|
|
|
|
|
if (!isAddable && (!album || !account)) return null
|
|
|
|
|
|
|
|
const title = isAddable ? 'New album' : album.get('title')
|
|
|
|
const subtitle = isAddable ? '' : `${album.get('count')} Items`
|
|
|
|
const to = isAddable ? undefined : `/${account.get('username')}/albums/${album.get('id')}`
|
|
|
|
const albumImageUrl = !!album ? album.getIn(['cover', 'preview_url'], null) : null
|
2020-12-21 00:28:32 +00:00
|
|
|
|
2020-12-16 07:39:07 +00:00
|
|
|
return (
|
2020-12-18 04:46:37 +00:00
|
|
|
<div className={[_s.d, _s.minW162PX, _s.px5, _s.flex1].join(' ')}>
|
2020-12-21 18:25:05 +00:00
|
|
|
<Button
|
|
|
|
noClasses
|
|
|
|
className={[_s.d, _s.noUnderline, _s.cursorPointer, _s.outlineNone, _s.bgTransparent].join(' ')}
|
|
|
|
to={to}
|
|
|
|
onClick={isAddable ? this.handleOnOpenAlbumCreate : undefined}
|
|
|
|
>
|
|
|
|
<div className={[_s.d, _s.w100PC, _s.mt5, _s.mb10].join(' ')}>
|
|
|
|
<div className={[_s.d, _s.w100PC, _s.pt100PC].join(' ')}>
|
|
|
|
<div className={[_s.d, _s.posAbs, _s.top0, _s.w100PC, _s.right0, _s.bottom0, _s.left0].join(' ')}>
|
2020-12-22 17:11:22 +00:00
|
|
|
<div className={[_s.d, _s.w100PC, _s.h100PC, _s.aiCenter, _s.jcCenter, _s.radiusSmall, _s.overflowHidden, _s.bgTertiary, _s.border1PX, _s.borderColorSecondary].join(' ')}>
|
2020-12-21 18:25:05 +00:00
|
|
|
{ isAddable && <Icon id='add' size='20px' /> }
|
2020-12-22 17:11:22 +00:00
|
|
|
{
|
|
|
|
albumImageUrl &&
|
|
|
|
<Image
|
|
|
|
height='100%'
|
|
|
|
width='100%'
|
|
|
|
className={_s.z3}
|
|
|
|
src={albumImageUrl}
|
|
|
|
/>
|
|
|
|
}
|
2020-12-18 04:46:37 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-12-21 18:25:05 +00:00
|
|
|
</div>
|
|
|
|
<div className={[_s.d, _s.w100PC, _s.pt7, _s.mb15].join(' ')}>
|
|
|
|
<Text weight='bold'>{title}</Text>
|
|
|
|
{ !isAddable && <Text color='secondary' size='small' className={_s.mt5}>{subtitle}</Text> }
|
|
|
|
</div>
|
|
|
|
</Button>
|
2020-12-18 04:46:37 +00:00
|
|
|
</div>
|
2020-12-16 07:39:07 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Album.propTypes = {
|
2020-12-22 17:11:22 +00:00
|
|
|
account: ImmutablePropTypes.map,
|
2020-12-16 07:39:07 +00:00
|
|
|
album: ImmutablePropTypes.map,
|
|
|
|
isAddable: PropTypes.bool,
|
|
|
|
}
|
|
|
|
|
2020-12-22 17:11:22 +00:00
|
|
|
const mapStateToProps = (state, { albumId }) => ({
|
|
|
|
album: state.getIn(['albums', albumId]),
|
|
|
|
})
|
|
|
|
|
2020-12-21 18:25:05 +00:00
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
openAlbumCreate() {
|
|
|
|
dispatch(openModal(MODAL_ALBUM_CREATE))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-12-22 17:11:22 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Album)
|