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

110 lines
2.8 KiB
JavaScript
Raw Normal View History

2020-02-24 21:56:07 +00:00
import { defineMessages, injectIntl } from 'react-intl'
2019-08-13 16:54:29 +01:00
import {
expandCommunityTimeline,
expandPublicTimeline,
2020-02-24 21:56:07 +00:00
} from '../../actions/timelines'
2019-08-13 16:54:29 +01:00
import {
connectCommunityStream,
connectPublicStream,
2020-02-24 21:56:07 +00:00
} from '../../actions/streaming'
import StatusListContainer from '../../containers/status_list_container'
2019-08-13 16:54:29 +01:00
const messages = defineMessages({
2020-02-24 21:56:07 +00:00
empty: { id: 'empty_column.community', defaultMessage: 'The community timeline is empty. Write something publicly to get the ball rolling!' },
})
2019-08-13 16:54:29 +01:00
const mapStateToProps = state => {
2020-02-24 21:56:07 +00:00
const allFediverse = state.getIn(['settings', 'community', 'other', 'allFediverse'])
const onlyMedia = state.getIn(['settings', 'community', 'other', 'onlyMedia'])
2019-08-13 16:54:29 +01:00
2020-02-24 21:56:07 +00:00
const timelineId = allFediverse ? 'public' : 'community'
2019-08-13 16:54:29 +01:00
return {
timelineId,
allFediverse,
onlyMedia,
2020-02-24 21:56:07 +00:00
}
}
2019-08-13 16:54:29 +01:00
2020-02-24 21:56:07 +00:00
export default
@connect(mapStateToProps)
2019-08-13 16:54:29 +01:00
@injectIntl
2020-01-29 21:54:39 +00:00
class CommunityTimeline extends PureComponent {
2019-08-13 16:54:29 +01:00
static contextTypes = {
router: PropTypes.object,
2020-02-24 21:56:07 +00:00
}
2019-08-13 16:54:29 +01:00
static propTypes = {
dispatch: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
onlyMedia: PropTypes.bool,
allFediverse: PropTypes.bool,
timelineId: PropTypes.string,
2020-02-24 21:56:07 +00:00
}
2019-08-13 16:54:29 +01:00
componentDidMount () {
2020-02-24 21:56:07 +00:00
const { dispatch, onlyMedia, allFediverse } = this.props
2019-08-13 16:54:29 +01:00
if (allFediverse) {
2020-02-24 21:56:07 +00:00
dispatch(expandPublicTimeline({ onlyMedia }))
this.disconnect = dispatch(connectPublicStream({ onlyMedia }))
2019-08-13 16:54:29 +01:00
}
else {
2020-02-24 21:56:07 +00:00
dispatch(expandCommunityTimeline({ onlyMedia }))
this.disconnect = dispatch(connectCommunityStream({ onlyMedia }))
2019-08-13 16:54:29 +01:00
}
}
componentDidUpdate (prevProps) {
if (prevProps.onlyMedia !== this.props.onlyMedia || prevProps.allFediverse !== this.props.allFediverse) {
2020-02-24 21:56:07 +00:00
const { dispatch, onlyMedia, allFediverse } = this.props
2019-08-13 16:54:29 +01:00
2020-02-24 21:56:07 +00:00
this.disconnect()
2019-08-13 16:54:29 +01:00
if (allFediverse) {
2020-02-24 21:56:07 +00:00
dispatch(expandPublicTimeline({ onlyMedia }))
this.disconnect = dispatch(connectPublicStream({ onlyMedia }))
2019-08-13 16:54:29 +01:00
}
else {
2020-02-24 21:56:07 +00:00
dispatch(expandCommunityTimeline({ onlyMedia }))
this.disconnect = dispatch(connectCommunityStream({ onlyMedia }))
2019-08-13 16:54:29 +01:00
}
}
}
componentWillUnmount () {
if (this.disconnect) {
2020-02-24 21:56:07 +00:00
this.disconnect()
this.disconnect = null
2019-08-13 16:54:29 +01:00
}
}
handleLoadMore = maxId => {
2020-02-24 21:56:07 +00:00
const { dispatch, onlyMedia, allFediverse } = this.props
2019-08-13 16:54:29 +01:00
if (allFediverse) {
2020-02-24 21:56:07 +00:00
dispatch(expandPublicTimeline({ maxId, onlyMedia }))
2019-08-13 16:54:29 +01:00
}
else {
2020-02-24 21:56:07 +00:00
dispatch(expandCommunityTimeline({ maxId, onlyMedia }))
2019-08-13 16:54:29 +01:00
}
}
render () {
2020-02-24 21:56:07 +00:00
const { intl, onlyMedia, timelineId } = this.props
const emptyMessage = intl.formatMessage(messages.empty)
2019-08-13 16:54:29 +01:00
return (
2020-02-24 21:56:07 +00:00
<StatusListContainer
scrollKey={`${timelineId}_timeline`}
timelineId={`${timelineId}${onlyMedia ? ':media' : ''}`}
onLoadMore={this.handleLoadMore}
emptyMessage={emptyMessage}
/>
)
2019-08-13 16:54:29 +01:00
}
}