import { observer } from "mobx-react";
import { useEffect } from "react";
import triggerResize from "../../Core/triggerResize";
import { useViewState } from "../Context";
import NotificationToast from "./NotificationToast";
import NotificationWindow from "./NotificationWindow";
const Notification = observer(() => {
const viewState = useViewState();
const notificationState = viewState?.terria.notificationState;
const notification = notificationState?.currentNotification;
const ignore =
typeof notification?.ignore === "function"
? notification.ignore()
: (notification?.ignore ?? false);
useEffect(() => {
if (ignore) {
notificationState.dismissCurrentNotification();
}
}, [notificationState, ignore]);
if (
viewState === undefined ||
notificationState === undefined ||
notification === undefined
) {
return null;
}
const close = () => {
// Force refresh once the notification is dispatched if .hideUi is set since once all the .hideUi's
// have been dispatched the UI will no longer be suppressed causing a change in the view state.
if (notification.hideUi) {
triggerResize();
}
notificationState.dismissCurrentNotification();
};
const confirm = () => {
if (notification.confirmAction !== undefined) {
notification.confirmAction();
}
close();
};
const deny = () => {
if (notification.denyAction !== undefined) {
notification.denyAction();
}
close();
};
return notification.showAsToast ? (
) : (
);
});
export default Notification;