'use client'
import {BellIcon} from '@heroicons/react/24/outline'
import {BellIcon as SolidBellIcon} from '@heroicons/react/24/solid'
import {NOTIFICATIONS_PER_PAGE} from 'common/notifications'
import {PrivateUser} from 'common/user'
import {usePathname} from 'next/navigation'
import {useEffect, useState} from 'react'
import {Row} from 'web/components/layout/row'
import {useGroupedUnseenNotifications} from 'web/hooks/use-notifications'
import {usePrivateUser} from 'web/hooks/use-user'
export function NotificationsIcon(props: {className?: string}) {
const privateUser = usePrivateUser()
const {className} = props
return (
{privateUser && }
)
}
export function SolidNotificationsIcon(props: {className?: string}) {
const privateUser = usePrivateUser()
const {className} = props
return (
{privateUser && }
)
}
function UnseenNotificationsBubble(props: {privateUser: PrivateUser}) {
const pathname = usePathname()
const {privateUser} = props
const [seen, setSeen] = useState(false)
const unseenSourceIdsToNotificationIds =
useGroupedUnseenNotifications(
privateUser.id,
// NOTIFICATION_TYPES_TO_SELECT
) ?? []
const unseenNotifs = Object.keys(unseenSourceIdsToNotificationIds).length
useEffect(() => {
if (pathname?.endsWith('notifications')) {
setSeen(pathname.endsWith('notifications'))
}
}, [pathname])
if (unseenNotifs === 0 || seen) {
return null
}
return (
{unseenNotifs > NOTIFICATIONS_PER_PAGE ? `${NOTIFICATIONS_PER_PAGE}+` : unseenNotifs}
)
}