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

107 lines
3.4 KiB
JavaScript
Raw Normal View History

2020-02-17 17:50:29 +00:00
import { Fragment } from 'react'
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-17 17:50:29 +00:00
import LinkFooter from '../components/link_footer'
import WhoToFollowPanel from '../components/panel/who_to_follow_panel'
2020-03-04 03:45:16 +00:00
import NotificationFilterPanel from '../components/panel/notification_filter_panel'
2020-02-17 17:50:29 +00:00
import TrendsPanel from '../components/panel/trends_panel'
2020-02-24 21:56:07 +00:00
import DefaultLayout from '../layouts/default_layout'
2020-02-17 17:50:29 +00:00
2020-03-26 03:11:32 +00:00
const messages = defineMessages({
2020-04-11 23:29:19 +01:00
notifications: { id: 'tabs_bar.notifications', defaultMessage: 'Notifications' },
2020-04-17 06:35:46 +01:00
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' },
2020-05-10 04:26:58 +01:00
follow_requests: { id: 'navigation_bar.follow_requests', defaultMessage: 'Follow requests' },
2020-04-11 23:29:19 +01:00
all: { id: 'notifications.filter.all', defaultMessage: 'All' },
})
2020-03-26 03:11:32 +00:00
2020-04-11 23:29:19 +01:00
const mapStateToProps = (state) => ({
2020-04-09 20:18:14 +01:00
selectedFilter: state.getIn(['notifications', 'filter', 'active']),
2020-04-11 23:29:19 +01:00
notificationCount: state.getIn(['notifications', 'unread']),
locked: !!state.getIn(['accounts', me, 'locked']),
2020-04-11 23:29:19 +01:00
})
2020-03-26 03:11:32 +00:00
const mapDispatchToProps = (dispatch) => ({
2020-04-11 23:29:19 +01:00
setFilter(value) {
2020-04-09 20:18:14 +01:00
dispatch(setFilter('active', value))
2020-03-26 03:11:32 +00:00
},
2020-04-11 23:29:19 +01:00
})
2020-03-26 03:11:32 +00:00
export default
@injectIntl
2020-04-11 23:29:19 +01:00
@connect(mapStateToProps, mapDispatchToProps)
2020-03-26 03:11:32 +00:00
class NotificationsPage extends PureComponent {
2020-04-09 20:18:14 +01:00
static contextTypes = {
router: PropTypes.object.isRequired,
}
2020-03-26 03:11:32 +00:00
static propTypes = {
2020-04-17 06:35:46 +01:00
children: PropTypes.node.isRequired,
2020-03-26 03:11:32 +00:00
intl: PropTypes.object.isRequired,
2020-04-11 23:29:19 +01:00
notificationCount: PropTypes.number.isRequired,
2020-04-17 06:35:46 +01:00
setFilter: PropTypes.func.isRequired,
selectedFilter: PropTypes.string.isRequired,
locked: PropTypes.bool,
2020-03-12 16:09:15 +00:00
}
2020-04-17 06:35:46 +01:00
onChangeActiveFilter(notificationType) {
this.props.setFilter(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,
notificationCount,
2020-04-11 23:29:19 +01:00
selectedFilter,
locked
2020-04-11 23:29:19 +01:00
} = 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
2020-02-17 17:50:29 +00:00
return (
<DefaultLayout
2020-04-11 23:29:19 +01:00
title={intl.formatMessage(messages.notifications)}
2020-02-17 17:50:29 +00:00
layout={(
<Fragment>
2020-03-04 03:45:16 +00:00
<NotificationFilterPanel />
2020-02-17 17:50:29 +00:00
<TrendsPanel />
<WhoToFollowPanel />
<LinkFooter />
</Fragment>
)}
2020-03-26 03:11:32 +00:00
tabs={tabs}
2020-02-17 17:50:29 +00:00
>
2020-04-11 23:29:19 +01:00
<PageTitle
badge={notificationCount}
path={intl.formatMessage(messages.notifications)}
/>
2020-02-17 17:50:29 +00:00
{children}
</DefaultLayout>
)
}
2020-04-28 06:33:58 +01:00
}{}