2020-12-06 04:47:48 +00:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2020-12-16 22:29:06 +00:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import { fetchAccount } from '../actions/accounts'
|
2020-12-06 04:47:48 +00:00
|
|
|
import DeckColumnHeader from './deck_column_header'
|
2020-12-16 22:29:06 +00:00
|
|
|
import Avatar from './avatar'
|
|
|
|
import DisplayName from './display_name'
|
|
|
|
import {
|
|
|
|
FONT_SIZES,
|
|
|
|
DEFAULT_FONT_SIZE,
|
|
|
|
FONT_SIZES_EXTRA_SMALL,
|
|
|
|
FONT_SIZES_SMALL,
|
|
|
|
FONT_SIZES_NORMAL,
|
|
|
|
FONT_SIZES_MEDIUM,
|
|
|
|
FONT_SIZES_LARGE,
|
|
|
|
FONT_SIZES_EXTRA_LARGE
|
|
|
|
} from '../constants'
|
2020-12-06 04:47:48 +00:00
|
|
|
|
2020-12-16 22:29:06 +00:00
|
|
|
class DeckColumn extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
state = {
|
|
|
|
width: 360, // default
|
|
|
|
refreshBool: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.setWidth()
|
|
|
|
|
|
|
|
const { accountId, account } = this.props
|
|
|
|
if (!!accountId || !account) {
|
|
|
|
this.props.onFetchAccount(accountId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
if (prevProps.fontSize !== this.props.fontSize) {
|
|
|
|
this.setWidth()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setWidth = () => {
|
|
|
|
const { fontSize } = this.props
|
|
|
|
|
|
|
|
let width = 360
|
|
|
|
switch (FONT_SIZES[fontSize]) {
|
|
|
|
case FONT_SIZES_EXTRA_SMALL:
|
|
|
|
width = 310
|
|
|
|
break;
|
|
|
|
case FONT_SIZES_SMALL:
|
|
|
|
width = 320
|
|
|
|
break;
|
|
|
|
case FONT_SIZES_NORMAL:
|
|
|
|
width = 335
|
|
|
|
break;
|
|
|
|
case FONT_SIZES_MEDIUM:
|
|
|
|
width = 350
|
|
|
|
break;
|
|
|
|
case FONT_SIZES_LARGE:
|
|
|
|
width = 365
|
|
|
|
break;
|
|
|
|
case FONT_SIZES_EXTRA_LARGE:
|
|
|
|
width = 385
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({ width })
|
|
|
|
}
|
|
|
|
|
|
|
|
handleOnRefresh = () => {
|
|
|
|
//hacky
|
|
|
|
this.setState({ refreshBool: true })
|
|
|
|
setTimeout(() => {
|
|
|
|
this.setState({ refreshBool: false })
|
|
|
|
}, 100);
|
|
|
|
}
|
2020-12-06 04:47:48 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
title,
|
|
|
|
subtitle,
|
|
|
|
icon,
|
|
|
|
children,
|
2020-12-09 04:15:33 +00:00
|
|
|
index,
|
2020-12-09 04:57:51 +00:00
|
|
|
noButtons,
|
2020-12-16 22:29:06 +00:00
|
|
|
noRefresh,
|
|
|
|
account,
|
2020-12-06 04:47:48 +00:00
|
|
|
} = this.props
|
2020-12-16 22:29:06 +00:00
|
|
|
const { width, refreshBool } = this.state
|
|
|
|
|
|
|
|
let newTitle = title
|
|
|
|
if (!!account) {
|
|
|
|
|
|
|
|
newTitle = (
|
|
|
|
<div className={[_s.d, _s.flexRow, _s.aiCenter].join(' ')}>
|
|
|
|
<Avatar account={account} noHover size={30} />
|
|
|
|
<div className={[_s.d, _s.ml10].join(' ')}>
|
|
|
|
<DisplayName account={account} noUsername isInline noHover />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2020-12-06 04:47:48 +00:00
|
|
|
|
|
|
|
return (
|
2020-12-16 22:29:06 +00:00
|
|
|
<div className={[_s.d, _s.px2, _s.bgSecondary, _s.h100VH].join(' ')} style={{ width: `${width}px` }}>
|
2020-12-06 04:47:48 +00:00
|
|
|
<div className={[_s.d, _s.w100PC, _s.bgPrimary, _s.h100VH].join(' ')}>
|
2020-12-09 04:57:51 +00:00
|
|
|
<DeckColumnHeader
|
2020-12-16 22:29:06 +00:00
|
|
|
title={newTitle}
|
2020-12-09 04:57:51 +00:00
|
|
|
subtitle={subtitle}
|
|
|
|
icon={icon}
|
|
|
|
index={index}
|
|
|
|
noButtons={noButtons}
|
2020-12-16 22:29:06 +00:00
|
|
|
noRefresh={noRefresh}
|
|
|
|
onRefresh={this.handleOnRefresh}
|
2020-12-09 04:57:51 +00:00
|
|
|
/>
|
2020-12-06 04:47:48 +00:00
|
|
|
<div className={[_s.d, _s.w100PC, _s.overflowYScroll, _s.boxShadowNone, _s.posAbs, _s.top60PX, _s.left0, _s.right0, _s.bottom0].join(' ')}>
|
2020-12-16 22:29:06 +00:00
|
|
|
{ !refreshBool && children}
|
2020-12-06 04:47:48 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-12-16 22:29:06 +00:00
|
|
|
const mapStateToProps = (state, { accountId }) => {
|
|
|
|
const account = !!accountId ? state.getIn(['accounts', accountId]) : null
|
|
|
|
|
|
|
|
return {
|
|
|
|
account,
|
|
|
|
fontSize: state.getIn(['settings', 'displayOptions', 'fontSize'], DEFAULT_FONT_SIZE),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
onFetchAccount(accountId) {
|
|
|
|
dispatch(fetchAccount(accountId))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-12-06 04:47:48 +00:00
|
|
|
DeckColumn.propTypes = {
|
|
|
|
title: PropTypes.string,
|
|
|
|
subtitle: PropTypes.string,
|
|
|
|
icon: PropTypes.string,
|
2020-12-09 04:15:33 +00:00
|
|
|
index: PropTypes.number,
|
2020-12-09 04:57:51 +00:00
|
|
|
noButtons: PropTypes.bool,
|
2020-12-16 22:29:06 +00:00
|
|
|
noRefresh: PropTypes.bool,
|
|
|
|
onRefresh: PropTypes.func,
|
|
|
|
accountId: PropTypes.string,
|
|
|
|
account: ImmutablePropTypes.map,
|
|
|
|
onFetchAccount: PropTypes.func.isRequired,
|
2020-12-06 04:47:48 +00:00
|
|
|
}
|
|
|
|
|
2020-12-16 22:29:06 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(DeckColumn)
|