import { Flex, BoxProps, Text } from '../../../general';
import { NotificationType } from './Notifications.types';
import { AppGroup } from './AppGroup';
import { Notification } from './Notification';
type NotificationListProps = {
settings?: {
[app: string]: {
groupByPath?: boolean;
};
};
groupByPath?: boolean;
containerWidth: number;
notifications: NotificationType[];
onAppLookup: (app: string) => { name: string; image: string; key: string };
onPathLookup: (
app: string,
path: string
) => {
title: string;
sigil?: any;
image?: string;
} | null;
onDismiss: (app: string, path: string, id: number) => void;
onDismissAll: (app: string, path?: string) => void;
onLinkClick: (app: string, path: string, link?: string) => void;
} & BoxProps;
export const NotificationList = ({
containerWidth,
notifications,
groupByPath = true,
justifyContent = 'flex-start',
onAppLookup,
onPathLookup,
onDismiss,
onDismissAll,
onLinkClick,
}: NotificationListProps) => {
let apps = notifications.map((n) => n.app);
// reduce notifications to unique paths
apps = apps.filter((app, index) => apps.indexOf(app) === index);
let appGroupedNotifications = apps.map((app) => {
let grouped = notifications.filter((n) => n.app === app);
return grouped;
});
if (notifications.length === 0) {
return (
// show empty state
No notifications
);
}
return (
{appGroupedNotifications.map((appNotifs) => {
const appInfo = onAppLookup(appNotifs[0].app);
if (appNotifs.length === 1) {
return (
);
}
return (
);
})}
);
};