gab-social/app/javascript/gabsocial/features/list_timeline.js

121 lines
3.2 KiB
JavaScript
Raw Normal View History

import React from 'react'
import PropTypes from 'prop-types'
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 { connectListStream } from '../actions/streaming'
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'
2020-04-29 23:32:49 +01:00
import Block from '../components/block'
const mapStateToProps = (state, props) => ({
list: state.getIn(['lists', props.params.id]),
2020-04-28 06:33:58 +01:00
})
2020-02-25 16:04:44 +00:00
export default
@connect(mapStateToProps)
class ListTimeline extends ImmutablePureComponent {
static contextTypes = {
router: PropTypes.object,
};
static propTypes = {
params: PropTypes.object.isRequired,
dispatch: PropTypes.func.isRequired,
2020-04-23 07:13:29 +01:00
list: PropTypes.oneOfType([
ImmutablePropTypes.map,
PropTypes.bool,
]),
intl: PropTypes.object.isRequired,
2020-04-28 06:33:58 +01:00
}
componentDidMount() {
2020-04-28 06:33:58 +01:00
this.handleConnect(this.props.params.id)
}
componentWillUnmount() {
2020-04-28 06:33:58 +01:00
this.handleDisconnect()
}
componentWillReceiveProps(nextProps) {
if (nextProps.params.id !== this.props.params.id) {
2020-04-28 06:33:58 +01:00
this.handleDisconnect()
this.handleConnect(nextProps.params.id)
}
}
handleConnect(id) {
2020-04-28 06:33:58 +01:00
const { dispatch } = this.props
2020-04-28 06:33:58 +01:00
dispatch(fetchList(id))
dispatch(expandListTimeline(id))
2020-04-28 06:33:58 +01:00
this.disconnect = dispatch(connectListStream(id))
}
handleDisconnect() {
if (this.disconnect) {
2020-04-28 06:33:58 +01:00
this.disconnect()
this.disconnect = null
}
}
2020-04-28 06:33:58 +01:00
handleLoadMore = (maxId) => {
const { id } = this.props.params
this.props.dispatch(expandListTimeline(id, { maxId }))
}
handleEditClick = () => {
2020-05-03 06:22:49 +01:00
this.props.dispatch(openModal('LIST_EDITOR', { id: this.props.params.id }))
}
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
if (typeof list === 'undefined') {
2020-04-28 06:33:58 +01:00
return <ColumnIndicator type='loading' />
} else if (list === false) {
2020-04-28 06:33:58 +01:00
return <ColumnIndicator type='missing' />
}
const emptyMessage = (
2020-05-03 06:22:49 +01:00
<div className={[_s.default, _s.py15, _s.px15, _s.alignItemsCenter].join(' ')}>
<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>
</div>
2020-04-28 06:33:58 +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
)
}
}