in src/components/Notifications/index.tsx [90:125]
addNotification: useCallback(
(...notification: Notification[]) => addNotification(...notification),
[addNotification],
),
removeNotification: useCallback(
(notification: Notification) => removeNotification(notification),
[removeNotification],
),
clearNotifications: useCallback(() => clearNotifications(), [clearNotifications]),
};
return <NotificationsContext.Provider value={contextValue}>{children}</NotificationsContext.Provider>;
};
export function useNotifications(): IContextProps {
const { notifications, addNotification, removeNotification, clearNotifications } = useContext(NotificationsContext);
return { notifications, addNotification, removeNotification, clearNotifications };
}
// Notification lifecycle
enum NotificationState {
// Mounted BUT not visible. Should turn to visible almost right away (Hidden)
Mounted,
// Normal visible (animating in)
Visible,
// Removing, but data still exists. (animating out)
Removed,
}
export const Notifications: React.FC = () => {
const { notifications, removeNotification, addNotification } = useNotifications();
const { subscribeToEvent, unsubscribeFromEvent } = useContext(PluginsContext);
// Lifecycle state of unique notifications
const [notificationState, setNotificationState] = useState<Record<string, NotificationState>>({});
const onRemove = (n: Notification) => {