2017-10-21 03:09:01 +08:00
|
|
|
/* eslint react/jsx-filename-extension: 0 */
|
2017-10-13 02:53:33 +08:00
|
|
|
import React from 'react';
|
2017-10-19 18:45:07 +08:00
|
|
|
import _ from 'lodash';
|
2017-10-13 02:53:33 +08:00
|
|
|
import { toast } from 'react-toastify';
|
|
|
|
|
2017-10-21 03:01:07 +08:00
|
|
|
import Toast from '/imports/ui/components/toast/component';
|
2017-10-13 02:53:33 +08:00
|
|
|
|
2017-10-19 18:45:07 +08:00
|
|
|
let lastToast = {
|
|
|
|
id: null,
|
|
|
|
message: null,
|
|
|
|
type: null,
|
|
|
|
icon: null,
|
|
|
|
};
|
|
|
|
|
2017-10-21 03:27:00 +08:00
|
|
|
export function notify(message, type = 'default', icon, options) {
|
2017-10-13 02:53:33 +08:00
|
|
|
const settings = {
|
|
|
|
type,
|
|
|
|
...options,
|
|
|
|
};
|
|
|
|
|
2017-10-19 18:45:07 +08:00
|
|
|
const { id: lastToastId, ...lastToastProps } = lastToast;
|
|
|
|
const toastProps = { message, type, icon };
|
|
|
|
|
2017-10-19 19:44:09 +08:00
|
|
|
if (!toast.isActive(lastToast.id) || !_.isEqual(lastToastProps, toastProps)) {
|
2017-10-19 18:45:07 +08:00
|
|
|
const id = toast(<Toast {...toastProps} />, settings);
|
|
|
|
|
|
|
|
lastToast = { id, ...toastProps };
|
2017-10-13 02:53:33 +08:00
|
|
|
}
|
2017-10-21 03:27:00 +08:00
|
|
|
}
|
2017-10-13 02:53:33 +08:00
|
|
|
|
2017-10-21 03:27:00 +08:00
|
|
|
export default { notify };
|