import { BellIcon } from '@heroicons/react/outline' import clsx from 'clsx' import { Row } from 'web/components/layout/row' import { useEffect, useState } from 'react' import { Notification } from 'common/notification' import { listenForNotifications } from 'web/lib/firebase/notifications' import { useUser } from 'web/hooks/use-user' import { useRouter } from 'next/router' export default function NotificationsIcon(props: { className?: string }) { const user = useUser() const [notifications, setNotifications] = useState< Notification[] | undefined >() const router = useRouter() useEffect(() => { if (router.pathname.endsWith('notifications')) return setNotifications([]) }, [router.pathname]) useEffect(() => { if (user) return listenForNotifications(user.id, setNotifications, true) }, [user]) return (
{notifications && notifications.length > 0 && (
{notifications.length}
)}
) }