gab-social/app/javascript/gabsocial/pages/notifications_page.js

108 lines
3.3 KiB
JavaScript
Raw Normal View History

import React from 'react'
import PropTypes from 'prop-types'
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'
import { me } from '../initial_state'
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'
import {
LinkFooter,
NotificationFilterPanel,
TrendsBreakingPanel,
UserSuggestionsPanel,
} from '../features/ui/util/async_components'
2020-02-17 17:50:29 +00:00
class NotificationsPage extends React.PureComponent {
2020-03-26 03:11:32 +00:00
2020-04-17 06:35:46 +01:00
onChangeActiveFilter(notificationType) {
this.props.dispatch(setFilter('active', notificationType))
2020-04-09 20:18:14 +01:00
if (notificationType === 'all') {
this.context.router.history.push('/notifications')
} 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,
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
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
const title = intl.formatMessage(messages.notifications)
2020-02-17 17:50:29 +00:00
return (
<DefaultLayout
title={title}
page='notifications'
layout={[
NotificationFilterPanel,
TrendsBreakingPanel,
UserSuggestionsPanel,
LinkFooter,
]}
2020-03-26 03:11:32 +00:00
tabs={tabs}
actions={[
{
icon: 'search',
to: '/search',
},
]}
2020-02-17 17:50:29 +00:00
>
<PageTitle badge={notificationCount} path={title} />
2020-02-17 17:50:29 +00:00
{children}
</DefaultLayout>
)
}
}
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))