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-04-28 06:33:58 +01:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
|
|
|
import { FormattedMessage } from 'react-intl'
|
|
|
|
import { expandListTimeline } from '../actions/timelines'
|
|
|
|
import { fetchList, deleteList } from '../actions/lists'
|
|
|
|
import { openModal } from '../actions/modal'
|
|
|
|
import StatusList from '../components/status_list'
|
|
|
|
import ColumnIndicator from '../components/column_indicator'
|
|
|
|
import Button from '../components/button'
|
|
|
|
import Text from '../components/text'
|
2019-08-07 06:02:36 +01:00
|
|
|
|
|
|
|
class ListTimeline extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object,
|
2020-04-28 06:33:58 +01:00
|
|
|
}
|
2019-08-07 06:02:36 +01:00
|
|
|
|
|
|
|
componentDidMount() {
|
2020-04-28 06:33:58 +01:00
|
|
|
this.handleConnect(this.props.params.id)
|
2019-08-07 06:02:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2020-04-28 06:33:58 +01:00
|
|
|
this.handleDisconnect()
|
2019-08-07 06:02:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
if (nextProps.params.id !== this.props.params.id) {
|
2020-04-28 06:33:58 +01:00
|
|
|
this.handleConnect(nextProps.params.id)
|
2019-08-07 06:02:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleConnect(id) {
|
2020-04-28 06:33:58 +01:00
|
|
|
const { dispatch } = this.props
|
2019-08-07 06:02:36 +01:00
|
|
|
|
2020-04-28 06:33:58 +01:00
|
|
|
dispatch(fetchList(id))
|
|
|
|
dispatch(expandListTimeline(id))
|
2019-08-07 06:02:36 +01:00
|
|
|
}
|
|
|
|
|
2020-04-28 06:33:58 +01:00
|
|
|
handleLoadMore = (maxId) => {
|
|
|
|
const { id } = this.props.params
|
|
|
|
this.props.dispatch(expandListTimeline(id, { maxId }))
|
2019-08-07 06:02:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
handleEditClick = () => {
|
2020-05-03 06:22:49 +01:00
|
|
|
this.props.dispatch(openModal('LIST_EDITOR', { id: this.props.params.id }))
|
2019-08-07 06:02:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2020-04-28 06:33:58 +01:00
|
|
|
const { list } = this.props
|
|
|
|
const { id } = this.props.params
|
|
|
|
const title = list ? list.get('title') : id
|
2019-08-07 06:02:36 +01:00
|
|
|
|
|
|
|
if (typeof list === 'undefined') {
|
2020-04-28 06:33:58 +01:00
|
|
|
return <ColumnIndicator type='loading' />
|
2019-08-07 06:02:36 +01:00
|
|
|
} else if (list === false) {
|
2020-04-28 06:33:58 +01:00
|
|
|
return <ColumnIndicator type='missing' />
|
2019-08-07 06:02:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const emptyMessage = (
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.py15, _s.px15, _s.aiCenter].join(' ')}>
|
2019-08-09 17:06:27 +01:00
|
|
|
<FormattedMessage
|
|
|
|
id='empty_column.list'
|
2020-04-28 06:33:58 +01:00
|
|
|
defaultMessage='There is nothing in this list yet. When members of this list post new statuses, they will appear here.'
|
|
|
|
/>
|
|
|
|
|
2020-05-03 06:22:49 +01:00
|
|
|
<div className={_s.mt10}>
|
|
|
|
<Button
|
|
|
|
onClick={this.handleEditClick}
|
|
|
|
className={[_s.mt10]}
|
|
|
|
>
|
|
|
|
<Text color='inherit' align='center'>
|
|
|
|
<FormattedMessage id='list.click_to_add' defaultMessage='Click here to add people' />
|
|
|
|
</Text>
|
|
|
|
</Button>
|
|
|
|
</div>
|
2019-08-07 06:02:36 +01:00
|
|
|
</div>
|
2020-04-28 06:33:58 +01:00
|
|
|
)
|
2019-08-07 06:02:36 +01:00
|
|
|
|
|
|
|
return (
|
2020-04-11 23:29:19 +01:00
|
|
|
<StatusList
|
2020-02-19 23:57:07 +00:00
|
|
|
scrollKey='list_timeline'
|
|
|
|
timelineId={`list:${id}`}
|
|
|
|
onLoadMore={this.handleLoadMore}
|
|
|
|
emptyMessage={emptyMessage}
|
|
|
|
/>
|
2020-04-28 06:33:58 +01:00
|
|
|
)
|
2019-08-07 06:02:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-08-19 01:22:15 +01:00
|
|
|
|
|
|
|
const mapStateToProps = (state, props) => ({
|
|
|
|
list: state.getIn(['lists', props.params.id]),
|
|
|
|
})
|
|
|
|
|
|
|
|
ListTimeline.propTypes = {
|
|
|
|
params: PropTypes.object.isRequired,
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
|
|
|
list: PropTypes.oneOfType([
|
|
|
|
ImmutablePropTypes.map,
|
|
|
|
PropTypes.bool,
|
|
|
|
]),
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(ListTimeline)
|