import React, { useEffect, useRef, useState } from 'react'; import classNames from 'classnames'; import { UR } from 'getstream'; import { Feed, useFeedContext, DefaultAT, DefaultUT } from '../context'; import { smartRender, ElementOrComponentOrLiteralType, PropsWithElementAttributes } from '../utils'; import { useOnClickOutside } from '../hooks/useOnClickOutside'; import { NotificationFeed, NotificationFeedProps } from './NotificationFeed'; import { DropdownPanel, DropdownPanelProps } from './DropdownPanel'; import { IconBadge } from './IconBadge'; export type NotificationDropdownProps< UT extends DefaultUT = DefaultUT, AT extends DefaultAT = DefaultAT, CT extends UR = UR, RT extends UR = UR, CRT extends UR = UR, PT extends UR = UR > = PropsWithElementAttributes< { Icon?: ElementOrComponentOrLiteralType; width?: number; } & Pick & NotificationFeedProps >; const NotificationDropdownInner = < UT extends DefaultUT = DefaultUT, AT extends DefaultAT = DefaultAT, CT extends UR = UR, RT extends UR = UR, CRT extends UR = UR, PT extends UR = UR >({ width, Footer, Header, Icon, right, className, style, ...feedProps }: NotificationDropdownProps) => { const feed = useFeedContext(); const [open, setOpen] = useState(false); const dropdownRef = useRef(null); useOnClickOutside(dropdownRef, () => setOpen(false), open); useEffect(() => { feed.refreshUnreadUnseen(); }, []); return (
{open && ( )}
); }; /** * IMPORTANT: Changing most of the props below doesn't result in the desired effect. * These settings related to feed management should be changed in the `sharedFeeds` prop of the [`StreamApp`](#streamapp) component. */ export const NotificationDropdown = < UT extends DefaultUT = DefaultUT, AT extends DefaultAT = DefaultAT, CT extends UR = UR, RT extends UR = UR, CRT extends UR = UR, PT extends UR = UR >({ width = 475, Footer, Header, Icon, right, feedGroup = 'notification', options, ...feedProps }: NotificationDropdownProps) => { const optionsWithDefaults = { ...options, mark_seen: options?.mark_seen ?? true }; return ( {...feedProps} feedGroup={feedGroup} options={optionsWithDefaults}> width={width} Footer={Footer} Header={Header} Icon={Icon} right={right} {...feedProps} feedGroup={feedGroup} options={optionsWithDefaults} /> ); };