|
|
@ -1,25 +1,35 @@
|
|
|
|
import { faExclamationTriangle } from "@fortawesome/free-solid-svg-icons";
|
|
|
|
import {
|
|
|
|
|
|
|
|
faExclamationTriangle,
|
|
|
|
|
|
|
|
faPaperPlane,
|
|
|
|
|
|
|
|
} from "@fortawesome/free-solid-svg-icons";
|
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
|
|
import { capitalize } from "lodash";
|
|
|
|
import { capitalize } from "lodash";
|
|
|
|
import React, { FunctionComponent, useCallback, useMemo } from "react";
|
|
|
|
import React, { FunctionComponent, useCallback, useMemo } from "react";
|
|
|
|
import { Toast } from "react-bootstrap";
|
|
|
|
import { ProgressBar, Toast } from "react-bootstrap";
|
|
|
|
import { useTimeoutWhen } from "rooks";
|
|
|
|
import { useTimeoutWhen } from "rooks";
|
|
|
|
import { siteRemoveNotifications } from "../../@redux/actions";
|
|
|
|
import {
|
|
|
|
|
|
|
|
siteRemoveNotifications,
|
|
|
|
|
|
|
|
siteRemoveProgress,
|
|
|
|
|
|
|
|
} from "../../@redux/actions";
|
|
|
|
import { useReduxAction, useReduxStore } from "../../@redux/hooks/base";
|
|
|
|
import { useReduxAction, useReduxStore } from "../../@redux/hooks/base";
|
|
|
|
import "./style.scss";
|
|
|
|
import "./style.scss";
|
|
|
|
|
|
|
|
|
|
|
|
export interface NotificationContainerProps {}
|
|
|
|
export interface NotificationContainerProps {}
|
|
|
|
|
|
|
|
|
|
|
|
const NotificationContainer: FunctionComponent<NotificationContainerProps> = () => {
|
|
|
|
const NotificationContainer: FunctionComponent<NotificationContainerProps> = () => {
|
|
|
|
const list = useReduxStore((s) => s.site.notifications);
|
|
|
|
const { progress, notifications } = useReduxStore((s) => s.site);
|
|
|
|
|
|
|
|
|
|
|
|
const items = useMemo(
|
|
|
|
const items = useMemo(() => {
|
|
|
|
() =>
|
|
|
|
const progressItems = progress.map((v) => (
|
|
|
|
list.map((v) => (
|
|
|
|
<ProgressToast key={v.id} {...v}></ProgressToast>
|
|
|
|
<NotificationToast key={v.id} {...v}></NotificationToast>
|
|
|
|
));
|
|
|
|
)),
|
|
|
|
|
|
|
|
[list]
|
|
|
|
const notificationItems = notifications.map((v) => (
|
|
|
|
);
|
|
|
|
<NotificationToast key={v.id} {...v}></NotificationToast>
|
|
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return [...progressItems, ...notificationItems];
|
|
|
|
|
|
|
|
}, [notifications, progress]);
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div className="alert-container">
|
|
|
|
<div className="alert-container">
|
|
|
|
<div className="toast-container">{items}</div>
|
|
|
|
<div className="toast-container">{items}</div>
|
|
|
@ -54,4 +64,39 @@ const NotificationToast: FunctionComponent<MessageHolderProps> = (props) => {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type ProgressHolderProps = ReduxStore.Progress & {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ProgressToast: FunctionComponent<ProgressHolderProps> = ({
|
|
|
|
|
|
|
|
id,
|
|
|
|
|
|
|
|
name,
|
|
|
|
|
|
|
|
value,
|
|
|
|
|
|
|
|
count,
|
|
|
|
|
|
|
|
}) => {
|
|
|
|
|
|
|
|
const removeProgress = useReduxAction(siteRemoveProgress);
|
|
|
|
|
|
|
|
const remove = useCallback(() => removeProgress(id), [removeProgress, id]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Auto remove
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
|
|
<Toast onClose={remove}>
|
|
|
|
|
|
|
|
<Toast.Body>
|
|
|
|
|
|
|
|
<div className="mb-2 mt-1">
|
|
|
|
|
|
|
|
<FontAwesomeIcon
|
|
|
|
|
|
|
|
className="mr-2"
|
|
|
|
|
|
|
|
icon={faPaperPlane}
|
|
|
|
|
|
|
|
></FontAwesomeIcon>
|
|
|
|
|
|
|
|
<span>{name}</span>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<ProgressBar
|
|
|
|
|
|
|
|
className="my-1"
|
|
|
|
|
|
|
|
animated
|
|
|
|
|
|
|
|
now={value / count}
|
|
|
|
|
|
|
|
max={1}
|
|
|
|
|
|
|
|
label={`${value}/${count}`}
|
|
|
|
|
|
|
|
></ProgressBar>
|
|
|
|
|
|
|
|
</Toast.Body>
|
|
|
|
|
|
|
|
</Toast>
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default NotificationContainer;
|
|
|
|
export default NotificationContainer;
|
|
|
|