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-11 23:29:19 +01:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl'
|
2020-03-26 03:11:32 +00:00
|
|
|
import { setFilter } from '../actions/notifications'
|
2020-06-07 18:27:08 +01:00
|
|
|
import { me } from '../initial_state'
|
2020-05-21 23:03:35 +01:00
|
|
|
import { NOTIFICATION_FILTERS } from '../constants'
|
2020-04-11 23:29:19 +01:00
|
|
|
import PageTitle from '../features/ui/util/page_title'
|
2020-02-24 21:56:07 +00:00
|
|
|
import DefaultLayout from '../layouts/default_layout'
|
2020-08-12 23:52:46 +01:00
|
|
|
import {
|
|
|
|
LinkFooter,
|
|
|
|
NotificationFilterPanel,
|
2020-11-07 05:19:04 +00:00
|
|
|
TrendsBreakingPanel,
|
2020-09-01 17:54:01 +01:00
|
|
|
UserSuggestionsPanel,
|
2020-08-12 23:52:46 +01:00
|
|
|
} from '../features/ui/util/async_components'
|
2020-02-17 17:50:29 +00:00
|
|
|
|
2020-08-17 21:07:16 +01:00
|
|
|
class NotificationsPage extends React.PureComponent {
|
2020-03-26 03:11:32 +00:00
|
|
|
|
2020-04-17 06:35:46 +01:00
|
|
|
onChangeActiveFilter(notificationType) {
|
2020-08-14 18:45:59 +01:00
|
|
|
this.props.dispatch(setFilter('active', notificationType))
|
2020-04-09 20:18:14 +01:00
|
|
|
|
|
|
|
if (notificationType === 'all') {
|
|
|
|
this.context.router.history.push('/notifications')
|
2020-06-07 18:27:08 +01:00
|
|
|
} else if (notificationType === 'follow_requests') {
|
|
|
|
this.context.router.history.push(`/notifications/follow_requests`)
|
2020-04-09 20:18:14 +01:00
|
|
|
} else {
|
2020-04-11 23:29:19 +01:00
|
|
|
this.context.router.history.push(`/notifications?view=${notificationType}`)
|
2020-04-09 20:18:14 +01:00
|
|
|
}
|
2020-03-26 03:11:32 +00:00
|
|
|
}
|
|
|
|
|
2020-02-17 17:50:29 +00:00
|
|
|
render() {
|
2020-04-11 23:29:19 +01:00
|
|
|
const {
|
|
|
|
children,
|
2020-04-17 06:35:46 +01:00
|
|
|
intl,
|
2020-08-14 18:45:59 +01:00
|
|
|
locked,
|
2020-04-17 06:35:46 +01:00
|
|
|
notificationCount,
|
2020-04-11 23:29:19 +01:00
|
|
|
selectedFilter,
|
|
|
|
} = this.props
|
2020-02-17 17:50:29 +00:00
|
|
|
|
2020-06-07 18:27:08 +01:00
|
|
|
let filters = NOTIFICATION_FILTERS
|
|
|
|
if (!locked && filters.indexOf('follow_requests') > -1) {
|
|
|
|
filters.splice(filters.indexOf('follow_requests'))
|
|
|
|
}
|
|
|
|
|
|
|
|
const tabs = filters.map((filter) => ({
|
2020-04-17 06:35:46 +01:00
|
|
|
title: intl.formatMessage(messages[filter]),
|
|
|
|
onClick: () => this.onChangeActiveFilter(filter),
|
2020-04-28 06:33:58 +01:00
|
|
|
active: selectedFilter.toLowerCase() === filter.toLowerCase(),
|
2020-04-17 06:35:46 +01:00
|
|
|
}))
|
2020-03-26 03:11:32 +00:00
|
|
|
|
2020-08-14 18:45:59 +01:00
|
|
|
const title = intl.formatMessage(messages.notifications)
|
|
|
|
|
2020-02-17 17:50:29 +00:00
|
|
|
return (
|
|
|
|
<DefaultLayout
|
2020-08-14 18:45:59 +01:00
|
|
|
title={title}
|
2020-07-16 05:05:08 +01:00
|
|
|
page='notifications'
|
|
|
|
layout={[
|
2020-08-12 23:52:46 +01:00
|
|
|
NotificationFilterPanel,
|
2020-11-07 05:19:04 +00:00
|
|
|
TrendsBreakingPanel,
|
2020-09-01 17:54:01 +01:00
|
|
|
UserSuggestionsPanel,
|
2020-08-12 23:52:46 +01:00
|
|
|
LinkFooter,
|
2020-07-16 05:05:08 +01:00
|
|
|
]}
|
2020-03-26 03:11:32 +00:00
|
|
|
tabs={tabs}
|
2020-11-05 17:35:35 +00:00
|
|
|
actions={[
|
|
|
|
{
|
|
|
|
icon: 'search',
|
|
|
|
to: '/search',
|
|
|
|
},
|
|
|
|
]}
|
2020-02-17 17:50:29 +00:00
|
|
|
>
|
2020-08-14 18:45:59 +01:00
|
|
|
<PageTitle badge={notificationCount} path={title} />
|
2020-02-17 17:50:29 +00:00
|
|
|
{children}
|
|
|
|
</DefaultLayout>
|
|
|
|
)
|
|
|
|
}
|
2020-08-14 18:45:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
notifications: { id: 'tabs_bar.notifications', defaultMessage: 'Notifications' },
|
|
|
|
mention: { id: 'notifications.filter.mentions', defaultMessage: 'Mentions' },
|
|
|
|
favourite: { id: 'likes', defaultMessage: 'Likes' },
|
|
|
|
reblog: { id: 'reposts', defaultMessage: 'Reposts' },
|
|
|
|
poll: { id: 'polls', defaultMessage: 'Poll' },
|
|
|
|
follow: { id: 'notifications.filter.follows', defaultMessage: 'Follows' },
|
|
|
|
follow_requests: { id: 'navigation_bar.follow_requests', defaultMessage: 'Follow requests' },
|
|
|
|
all: { id: 'notifications.filter.all', defaultMessage: 'All' },
|
|
|
|
})
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => ({
|
|
|
|
selectedFilter: state.getIn(['notifications', 'filter', 'active']),
|
|
|
|
notificationCount: state.getIn(['notifications', 'unread']),
|
|
|
|
locked: !!state.getIn(['accounts', me, 'locked']),
|
|
|
|
})
|
|
|
|
|
|
|
|
NotificationsPage.contextTypes = {
|
|
|
|
router: PropTypes.object.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
NotificationsPage.propTypes = {
|
|
|
|
children: PropTypes.node.isRequired,
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
locked: PropTypes.bool,
|
|
|
|
notificationCount: PropTypes.number.isRequired,
|
|
|
|
selectedFilter: PropTypes.string.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default injectIntl(connect(mapStateToProps)(NotificationsPage))
|