Enhancement: Show unread marker on widget bubble (#3390)

* add unread marker

* add removeClass in IFramehelper

* Update app/javascript/sdk/sdk.js

* Update app/javascript/sdk/sdk.js

Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com>
This commit is contained in:
Sanju
2021-11-25 20:25:14 +05:30
committed by GitHub
parent b0370ce44d
commit 2c3c1888f1
3 changed files with 38 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ import {
wootOn, wootOn,
addClass, addClass,
loadCSS, loadCSS,
removeClass,
onLocationChangeListener, onLocationChangeListener,
} from './DOMHelpers'; } from './DOMHelpers';
import { import {
@@ -197,6 +198,18 @@ export const IFrameHelper = {
removeUnreadClass(); removeUnreadClass();
}, },
handleNotificationDot: event => {
const bubbleElement = document.querySelector('.woot-widget-bubble');
if (
event.unreadMessageCount > 0 &&
!bubbleElement.classList.contains('unread-notification')
) {
addClass(bubbleElement, 'unread-notification');
} else if (event.unreadMessageCount === 0) {
removeClass(bubbleElement, 'unread-notification');
}
},
closeChat: () => { closeChat: () => {
onBubbleClick({ toggleValue: false }); onBubbleClick({ toggleValue: false });
}, },

View File

@@ -37,6 +37,19 @@ export const SDK_CSS = `.woot-widget-holder {
user-select: none; user-select: none;
} }
.woot-widget-bubble.unread-notification::after {
content: '';
position: absolute;
width: 12px;
height: 12px;
background: #ff4040;
border-radius: 100%;
top: 0px;
right: 0px;
border: 2px solid #ffffff;
transition: background 0.2s ease;
}
.woot-widget-bubble.woot-widget--expanded { .woot-widget-bubble.woot-widget--expanded {
bottom: 24px; bottom: 24px;
display: flex; display: flex;

View File

@@ -200,12 +200,23 @@ export default {
unreadMessageCount, unreadMessageCount,
}); });
this.setIframeHeight(this.isMobile); this.setIframeHeight(this.isMobile);
this.handleUnreadNotificationDot();
} }
}, },
unsetUnreadView() { unsetUnreadView() {
if (this.isIFrame) { if (this.isIFrame) {
IFrameHelper.sendMessage({ event: 'resetUnreadMode' }); IFrameHelper.sendMessage({ event: 'resetUnreadMode' });
this.setIframeHeight(); this.setIframeHeight();
this.handleUnreadNotificationDot();
}
},
handleUnreadNotificationDot() {
const { unreadMessageCount } = this;
if (this.isIFrame) {
IFrameHelper.sendMessage({
event: 'handleNotificationDot',
unreadMessageCount,
});
} }
}, },
createWidgetEvents(message) { createWidgetEvents(message) {
@@ -281,6 +292,7 @@ export default {
} }
this.showUnreadView = false; this.showUnreadView = false;
this.showCampaignView = false; this.showCampaignView = false;
this.handleUnreadNotificationDot();
} else if (message.event === 'toggle-open') { } else if (message.event === 'toggle-open') {
this.isWidgetOpen = message.isOpen; this.isWidgetOpen = message.isOpen;
this.toggleOpen(); this.toggleOpen();