lbry-desktop/ui/component/notificationHeaderButton/view.jsx

45 lines
1.1 KiB
React
Raw Normal View History

2020-07-23 16:22:57 +02:00
// @flow
import * as PAGES from 'constants/pages';
import * as ICONS from 'constants/icons';
import React from 'react';
import Icon from 'component/common/icon';
2020-08-11 22:32:03 +02:00
import NotificationBubble from 'component/notificationBubble';
2020-07-23 16:22:57 +02:00
import Button from 'component/button';
import { useHistory } from 'react-router';
type Props = {
unreadCount: number,
doReadNotifications: () => void,
user: ?User,
};
export default function NotificationHeaderButton(props: Props) {
2020-08-21 21:44:54 +02:00
const { unreadCount, doReadNotifications, user } = props;
2020-07-23 16:22:57 +02:00
const notificationsEnabled = user && user.experimental_ui;
const { push } = useHistory();
function handleMenuClick() {
if (unreadCount > 0) {
doReadNotifications();
}
push(`/$/${PAGES.NOTIFICATIONS}`);
}
if (!notificationsEnabled) {
return null;
}
return (
<Button
onClick={handleMenuClick}
aria-label={__('Notifications')}
title={__('Notifications')}
className="header__navigation-item menu__title header__navigation-item--icon"
>
<Icon size={18} icon={ICONS.NOTIFICATION} aria-hidden />
2020-08-11 22:32:03 +02:00
<NotificationBubble />
2020-07-23 16:22:57 +02:00
</Button>
);
}