import { faExclamationTriangle, faPaperPlane, } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { capitalize } from "lodash"; import React, { FunctionComponent, useCallback, useEffect, useMemo, } from "react"; import { ProgressBar, Toast } from "react-bootstrap"; import { siteRemoveNotifications, siteRemoveProgress, } from "../../@redux/actions"; import { useReduxAction, useReduxStore } from "../../@redux/hooks/base"; import "./style.scss"; export interface NotificationContainerProps {} const NotificationContainer: FunctionComponent = () => { const { progress, notifications } = useReduxStore((s) => s.site); const items = useMemo(() => { const progressItems = progress.map((v) => ( )); const notificationItems = notifications.map((v) => ( )); return [...progressItems, ...notificationItems]; }, [notifications, progress]); return (
{items}
); }; type MessageHolderProps = ReduxStore.Notification & {}; const NotificationToast: FunctionComponent = (props) => { const { message, type, id, timeout } = props; const removeNotification = useReduxAction(siteRemoveNotifications); const remove = useCallback(() => removeNotification(id), [ removeNotification, id, ]); useEffect(() => { const handle = setTimeout(remove, timeout); return () => { clearTimeout(handle); }; }, [props, remove, timeout]); return ( {capitalize(type)} {message} ); }; type ProgressHolderProps = ReduxStore.Progress & {}; const ProgressToast: FunctionComponent = ({ id, header, name, value, count, }) => { const removeProgress = useReduxAction(siteRemoveProgress); const remove = useCallback(() => removeProgress(id), [removeProgress, id]); useEffect(() => { const handle = setTimeout(remove, 10 * 1000); return () => { clearTimeout(handle); }; }, [value, remove]); const incomplete = value / count < 1; return ( {header} {name} ); }; export default NotificationContainer;