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

42 lines
1.2 KiB
React
Raw Normal View History

2020-07-23 16:22:57 +02:00
// @flow
2021-12-21 13:42:28 +01:00
import 'scss/component/_header.scss';
2021-12-20 13:32:32 +01:00
import { ENABLE_UI_NOTIFICATIONS } from 'config';
import { useHistory } from 'react-router';
2020-07-23 16:22:57 +02:00
import * as ICONS from 'constants/icons';
2021-12-20 13:32:32 +01:00
import * as PAGES from 'constants/pages';
import Button from 'component/button';
2020-07-23 16:22:57 +02:00
import Icon from 'component/common/icon';
2020-08-11 22:32:03 +02:00
import NotificationBubble from 'component/notificationBubble';
2021-12-20 13:32:32 +01:00
import React from 'react';
import Tooltip from 'component/common/tooltip';
2020-07-23 16:22:57 +02:00
type Props = {
2020-12-14 19:52:17 +01:00
unseenCount: number,
2020-07-23 16:22:57 +02:00
user: ?User,
2021-12-20 13:32:32 +01:00
doSeeAllNotifications: () => void,
2020-07-23 16:22:57 +02:00
};
export default function NotificationHeaderButton(props: Props) {
2021-12-20 13:32:32 +01:00
const { unseenCount, user, doSeeAllNotifications } = props;
2020-07-23 16:22:57 +02:00
const { push } = useHistory();
2021-12-20 13:32:32 +01:00
const notificationsEnabled = ENABLE_UI_NOTIFICATIONS || (user && user.experimental_ui);
2020-07-23 16:22:57 +02:00
function handleMenuClick() {
2021-12-20 13:32:32 +01:00
if (unseenCount > 0) doSeeAllNotifications();
2020-07-23 16:22:57 +02:00
push(`/$/${PAGES.NOTIFICATIONS}`);
}
2021-12-20 13:32:32 +01:00
if (!notificationsEnabled) return null;
2020-07-23 16:22:57 +02:00
return (
<Tooltip title={__('Notifications')}>
2021-12-21 13:42:28 +01:00
<Button onClick={handleMenuClick} className="header__navigationItem--icon">
<Icon size={18} icon={ICONS.NOTIFICATION} aria-hidden />
<NotificationBubble />
</Button>
</Tooltip>
2020-07-23 16:22:57 +02:00
);
}