OHIF with Cornerstone3D 2.0 (#4347)

This commit is contained in:
Alireza authored and GitHub committed 2024-11-06 07:15:27 -05:00
1 parent 8981a61b8c
commit 7ce7127d7c
803 files changed
+32760 -15893

No files matched your search

@@ -1,6 +1,6 @@
import React, { useState, createContext, useContext, useCallback, useEffect } from 'react';
import React, { createContext, useContext, useCallback, useEffect, ReactNode } from 'react';
import PropTypes from 'prop-types';
import { Toaster, toast } from 'sonner';
import { Toaster, toast } from '../components';
const NotificationContext = createContext(null);
@@ -15,38 +15,41 @@ const NotificationProvider = ({ children, service }) => {
type: 'info', // info, success, error
};
const [notificationItems, setNotificationItems] = useState([]);
const show = useCallback(options => {
const { title, message, duration, position, type } = { ...DEFAULT_OPTIONS, ...options };
const id = toast[type](message, {
const { title, message, duration, position, type, promise } = {
...DEFAULT_OPTIONS,
...options,
};
if (promise) {
return toast.promise(promise, {
loading: title || 'Loading...',
success: (data: unknown) => ({
title: title || 'Success',
description: typeof message === 'function' ? message(data) : message,
}),
error: (err: unknown) => ({
title: title || 'Error',
description: typeof message === 'function' ? message(err) : message,
}),
});
}
return toast[type](title, {
duration,
position,
render: () => (
<div>
<strong>{title}</strong>
<p>{message}</p>
</div>
),
description: message,
});
setNotificationItems(state => [...state, { id, ...options }]);
}, []);
const hide = useCallback(id => {
toast.dismiss(id);
setNotificationItems(state => state.filter(item => item.id !== id));
}, []);
const hideAll = useCallback(() => {
toast.dismiss();
setNotificationItems([]);
}, []);
useEffect(() => {
window.notification = { show, hide, hideAll };
}, [show, hide, hideAll]);
/**
* Sets the implementation of a notification service that can be used by extensions.
*
@@ -59,7 +62,7 @@ const NotificationProvider = ({ children, service }) => {
}, [service, hide, show]);
return (
<NotificationContext.Provider value={{ show, hide, hideAll, notificationItems }}>
<NotificationContext.Provider value={{ show, hide, hideAll }}>
<Toaster position="bottom-right" />
{children}
</NotificationContext.Provider>