|
@@ -74,6 +74,7 @@ class NotificationList extends BaseComponent<NotificationListProps, Notification
|
|
this.state = {
|
|
this.state = {
|
|
notices: [],
|
|
notices: [],
|
|
removedItems: [],
|
|
removedItems: [],
|
|
|
|
+ updatedItems: []
|
|
};
|
|
};
|
|
this.noticeStorage = [];
|
|
this.noticeStorage = [];
|
|
this.removeItemStorage = [];
|
|
this.removeItemStorage = [];
|
|
@@ -86,18 +87,18 @@ class NotificationList extends BaseComponent<NotificationListProps, Notification
|
|
get adapter(): NotificationListAdapter {
|
|
get adapter(): NotificationListAdapter {
|
|
return {
|
|
return {
|
|
...super.adapter,
|
|
...super.adapter,
|
|
- updateNotices: (notices: NoticeInstance[], removedItems: NoticeInstance[] = []) => {
|
|
|
|
|
|
+ updateNotices: (notices: NoticeInstance[], removedItems: NoticeInstance[] = [], updatedItems: NoticeInstance[] = []) => {
|
|
this.noticeStorage = [...notices];
|
|
this.noticeStorage = [...notices];
|
|
this.removeItemStorage = [...removedItems];
|
|
this.removeItemStorage = [...removedItems];
|
|
// setState is async sometimes and react often merges state, so use "this" , make sure other code always get right data.
|
|
// setState is async sometimes and react often merges state, so use "this" , make sure other code always get right data.
|
|
- this.setState({ notices, removedItems });
|
|
|
|
|
|
+ this.setState({ notices, removedItems, updatedItems });
|
|
},
|
|
},
|
|
getNotices: () => this.noticeStorage,
|
|
getNotices: () => this.noticeStorage,
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
static addNotice(notice: NoticeProps) {
|
|
static addNotice(notice: NoticeProps) {
|
|
- const id = getUuid('notification');
|
|
|
|
|
|
+ const id = notice.id ?? getUuid('notification');
|
|
if (!ref) {
|
|
if (!ref) {
|
|
const { getPopupContainer } = notice;
|
|
const { getPopupContainer } = notice;
|
|
const div = document.createElement('div');
|
|
const div = document.createElement('div');
|
|
@@ -117,7 +118,12 @@ class NotificationList extends BaseComponent<NotificationListProps, Notification
|
|
ref.add({ ...notice, id });
|
|
ref.add({ ...notice, id });
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
- ref.add({ ...notice, id });
|
|
|
|
|
|
+ if (ref.has(`${id}`)) {
|
|
|
|
+ ref.update(id, notice);
|
|
|
|
+ } else {
|
|
|
|
+ ref.add({ ...notice, id });
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
return id;
|
|
return id;
|
|
}
|
|
}
|
|
@@ -185,16 +191,25 @@ class NotificationList extends BaseComponent<NotificationListProps, Notification
|
|
|
|
|
|
add = (noticeOpts: NoticeProps) => this.foundation.addNotice(noticeOpts);
|
|
add = (noticeOpts: NoticeProps) => this.foundation.addNotice(noticeOpts);
|
|
|
|
|
|
|
|
+ has = (id: string) => this.foundation.has(id);
|
|
|
|
+
|
|
remove = (id: string | number) => {
|
|
remove = (id: string | number) => {
|
|
this.foundation.removeNotice(String(id));
|
|
this.foundation.removeNotice(String(id));
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ update = (id: string|number, opts: NoticeProps)=>{
|
|
|
|
+ return this.foundation.update(id, opts);
|
|
|
|
+ }
|
|
|
|
+
|
|
destroyAll = () => this.foundation.destroyAll();
|
|
destroyAll = () => this.foundation.destroyAll();
|
|
|
|
|
|
renderNoticeInPosition = (
|
|
renderNoticeInPosition = (
|
|
notices: NoticeInstance[],
|
|
notices: NoticeInstance[],
|
|
position: NoticePosition,
|
|
position: NoticePosition,
|
|
- removedItems: NoticeInstance[] = []
|
|
|
|
|
|
+ removedItems: NoticeInstance[] = [],
|
|
|
|
+ updatedItems: NoticeInstance[] = []
|
|
) => {
|
|
) => {
|
|
const className = cls(cssClasses.LIST);
|
|
const className = cls(cssClasses.LIST);
|
|
// TODO notifyOnClose
|
|
// TODO notifyOnClose
|
|
@@ -211,6 +226,12 @@ class NotificationList extends BaseComponent<NotificationListProps, Notification
|
|
{({ animationClassName, animationEventsNeedBind, isAnimating }) => {
|
|
{({ animationClassName, animationEventsNeedBind, isAnimating }) => {
|
|
return isRemoved && !isAnimating ? null : <Notice
|
|
return isRemoved && !isAnimating ? null : <Notice
|
|
{...notice}
|
|
{...notice}
|
|
|
|
+ ref={(notice)=>{
|
|
|
|
+ if (notice && updatedItems.some(item=>item.id===notice.props.id)) {
|
|
|
|
+ notice.foundation.setState({ duration: notice.props.duration });
|
|
|
|
+ notice.foundation.restartCloseTimer();
|
|
|
|
+ }
|
|
|
|
+ }}
|
|
className={cls({
|
|
className={cls({
|
|
[notice.className]: Boolean(notice.className),
|
|
[notice.className]: Boolean(notice.className),
|
|
[animationClassName]: true,
|
|
[animationClassName]: true,
|
|
@@ -242,7 +263,7 @@ class NotificationList extends BaseComponent<NotificationListProps, Notification
|
|
|
|
|
|
render() {
|
|
render() {
|
|
let { notices } = this.state;
|
|
let { notices } = this.state;
|
|
- const { removedItems } = this.state;
|
|
|
|
|
|
+ const { removedItems, updatedItems } = this.state;
|
|
notices = Array.from(new Set([...notices, ...removedItems]));
|
|
notices = Array.from(new Set([...notices, ...removedItems]));
|
|
const noticesInPosition: NoticesInPosition = {
|
|
const noticesInPosition: NoticesInPosition = {
|
|
top: [],
|
|
top: [],
|
|
@@ -261,7 +282,7 @@ class NotificationList extends BaseComponent<NotificationListProps, Notification
|
|
const noticesList = Object.entries(noticesInPosition).map(obj => {
|
|
const noticesList = Object.entries(noticesInPosition).map(obj => {
|
|
const pos = obj[0];
|
|
const pos = obj[0];
|
|
const noticesInPos = obj[1];
|
|
const noticesInPos = obj[1];
|
|
- return this.renderNoticeInPosition(noticesInPos, pos as NoticePosition, removedItems);
|
|
|
|
|
|
+ return this.renderNoticeInPosition(noticesInPos, pos as NoticePosition, removedItems, updatedItems);
|
|
});
|
|
});
|
|
|
|
|
|
return <React.Fragment>{noticesList}</React.Fragment>;
|
|
return <React.Fragment>{noticesList}</React.Fragment>;
|