import { Flex, BoxProps, FlexProps, Text, Button, Icon, Avatar, NoScrollBar, } from '../../../general'; import styled from 'styled-components'; import { NotificationType } from './Notifications.types'; import { NotifAppRow, Notification } from './Notification'; import { useState } from 'react'; type AppGroupProps = { appInfo: { image: string; name: string; key: string; }; groupByPath?: boolean; containerWidth: number; notifications: NotificationType[]; onPathLookup: ( app: string, path: string ) => { title: string; sigil?: any; image?: string; } | null; onLinkClick: (app: string, path: string, link?: string) => void; onDismiss: (app: string, path: string, id: number) => void; onDismissAll: (app: string, path?: string) => void; } & BoxProps; export const AppGroup = ({ groupByPath = false, notifications, containerWidth, appInfo, onPathLookup, onDismiss, onDismissAll, onLinkClick, }: AppGroupProps) => { let paths = notifications.map((n) => n.path); // reduce notifications to unique paths paths = paths.filter((path, index) => paths.indexOf(path) === index); let groupedNotifications = paths.map((path) => { let grouped = notifications.filter((n) => n.path === path); return grouped; }); const [pathExpandMap, setPathExpandMap] = useState<{ [path: string]: boolean; }>(paths.reduce((acc, path) => ({ ...acc, [path]: false }), {})); const outerOffset = 12; const innerOffset = 20; const renderedNotifications = ( notifs: NotificationType[], paddingOffset: number ) => { return notifs.map((n) => { return ( ); }); }; return ( {!groupByPath ? renderedNotifications(notifications, outerOffset) : groupedNotifications.map((notifs) => { const metadata = onPathLookup(notifs[0].app, notifs[0].path); if (!metadata) return renderedNotifications(notifs, outerOffset); let title = metadata.title; let avatar; if (metadata?.image) { avatar = ( ); } else if (metadata.sigil) { avatar = ( ); } const isExpanded = pathExpandMap[notifs[0].path]; return ( {avatar} {title} {notifs.length > 1 && ( { evt.stopPropagation(); setPathExpandMap({ ...pathExpandMap, [notifs[0].path]: !isExpanded, }); }} > )} { evt.stopPropagation(); onDismissAll(notifs[0].app, notifs[0].path); }} > {isExpanded ? ( renderedNotifications(notifs, innerOffset) ) : ( )} ); })} { appInfo && onDismissAll(appInfo.key); }, ]} /> ); }; type AppGroupContainerProps = { hasImage?: boolean; } & FlexProps; const AppGroupContainer = styled(Flex)` display: inline-flex; gap: 8px; flex-direction: column; justify-content: space-between; padding: 6px; color: rgba(var(--rlm-text-rgba)); border-radius: var(--rlm-border-radius-6); background: rgba(var(--rlm-card-rgba), 0.7); transition: var(--transition); `; const PathContainer = styled(Flex)` display: inline-flex; gap: 0px; position: relative; flex-direction: column; justify-content: space-between; padding: 4px 4px 4px 4px; color: rgba(var(--rlm-text-rgba)); border-radius: var(--rlm-border-radius-6); &:hover { transition: var(--transition); background: rgba(0, 0, 0, 0.04); } transition: var(--transition); `;