Bug: Fix missing close button on mobile chat window (#600)

Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
Nithin David Thomas 2020-03-07 23:39:41 +05:30 committed by GitHub
parent 8b4df986bf
commit 60dc564f37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 89 additions and 35 deletions

View file

@ -82,7 +82,7 @@ linters:
enabled: true enabled: true
ImportantRule: ImportantRule:
enabled: true enabled: false
ImportPath: ImportPath:
enabled: true enabled: true

View file

@ -131,6 +131,7 @@ const IFrameHelper = {
body.appendChild(holder); body.appendChild(holder);
IFrameHelper.initPostMessageCommunication(); IFrameHelper.initPostMessageCommunication();
IFrameHelper.initLocationListener(); IFrameHelper.initLocationListener();
IFrameHelper.initWindowSizeListener();
}, },
getAppFrame: () => document.getElementById('chatwoot_live_chat_widget'), getAppFrame: () => document.getElementById('chatwoot_live_chat_widget'),
sendMessage: (key, value) => { sendMessage: (key, value) => {
@ -146,6 +147,7 @@ const IFrameHelper = {
IFrameHelper.sendMessage('config-set', {}); IFrameHelper.sendMessage('config-set', {});
IFrameHelper.onLoad(message.config.channelConfig); IFrameHelper.onLoad(message.config.channelConfig);
IFrameHelper.setCurrentUrl(); IFrameHelper.setCurrentUrl();
IFrameHelper.toggleCloseButton();
}, },
set_auth_token: message => { set_auth_token: message => {
Cookies.set('cw_conversation', message.authToken); Cookies.set('cw_conversation', message.authToken);
@ -173,6 +175,11 @@ const IFrameHelper = {
IFrameHelper.setCurrentUrl(); IFrameHelper.setCurrentUrl();
}; };
}, },
initWindowSizeListener: () => {
wootOn(window, 'resize', () => {
IFrameHelper.toggleCloseButton();
});
},
onLoad: ({ widget_color: widgetColor }) => { onLoad: ({ widget_color: widgetColor }) => {
const iframe = IFrameHelper.getAppFrame(); const iframe = IFrameHelper.getAppFrame();
iframe.style.visibility = ''; iframe.style.visibility = '';
@ -205,6 +212,14 @@ const IFrameHelper = {
refererURL: window.location.href, refererURL: window.location.href,
}); });
}, },
toggleCloseButton: () => {
console.log(window.matchMedia('(max-width: 668px)'));
if (window.matchMedia('(max-width: 668px)').matches) {
IFrameHelper.sendMessage('toggle-close-button', { showClose: true });
} else {
IFrameHelper.sendMessage('toggle-close-button', { showClose: false });
}
},
}; };
function loadIframe({ baseUrl, websiteToken }) { function loadIframe({ baseUrl, websiteToken }) {

View file

@ -1,5 +1,5 @@
<template> <template>
<div id="app" class="woot-widget-wrap"> <div id="app" class="woot-widget-wrap" :class="{ 'is-mobile': isMobile }">
<router-view /> <router-view />
</div> </div>
</template> </template>
@ -11,6 +11,11 @@ import { IFrameHelper } from 'widget/helpers/utils';
export default { export default {
name: 'App', name: 'App',
data() {
return {
isMobile: false,
};
},
mounted() { mounted() {
const { website_token: websiteToken = '' } = window.chatwootWebChannel; const { website_token: websiteToken = '' } = window.chatwootWebChannel;
if (IFrameHelper.isIFrame()) { if (IFrameHelper.isIFrame()) {
@ -40,6 +45,8 @@ export default {
this.scrollConversationToBottom(); this.scrollConversationToBottom();
} else if (message.event === 'set-current-url') { } else if (message.event === 'set-current-url') {
window.refererURL = message.refererURL; window.refererURL = message.refererURL;
} else if (message.event === 'toggle-close-button') {
this.isMobile = message.showClose;
} }
}); });
}, },

View file

@ -17,3 +17,36 @@ body {
.woot-widget-wrap { .woot-widget-wrap {
height: 100%; height: 100%;
} }
.close-button {
cursor: pointer;
position: relative;
width: $space-two;
&::before,
&::after {
background-color: $color-heading;
content: ' ';
height: $space-normal;
left: $space-small;
position: absolute;
top: $space-micro;
width: 2px;
}
&::before {
transform: rotate(45deg);
}
&::after {
transform: rotate(-45deg);
}
}
.is-mobile {
.header-wrap {
.close-button {
display: block !important;
}
}
}

View file

@ -85,6 +85,7 @@ export default {
.avatar-wrap { .avatar-wrap {
height: $space-medium; height: $space-medium;
width: $space-medium; width: $space-medium;
flex-shrink: 0;
.user-thumbnail-box { .user-thumbnail-box {
margin-top: -$space-large; margin-top: -$space-large;

View file

@ -3,7 +3,7 @@
<h2 class="title"> <h2 class="title">
{{ title }} {{ title }}
</h2> </h2>
<span class="close" @click="closeWindow"></span> <span class="close-button" @click="closeWindow"></span>
</header> </header>
</template> </template>
@ -54,27 +54,8 @@ export default {
color: $color-heading; color: $color-heading;
} }
.close { .close-button {
cursor: pointer; display: none;
position: relative;
width: $space-two;
&:before,
&:after {
position: absolute;
left: $space-small;
top: $space-smaller;
content: ' ';
height: $space-normal;
width: 2px;
background-color: $color-heading;
}
&:before {
transform: rotate(45deg);
}
&:after {
transform: rotate(-45deg);
}
} }
} }
</style> </style>

View file

@ -1,22 +1,22 @@
<template> <template>
<header class="header-expanded"> <header class="header-expanded">
<div> <!-- <img
<!-- <img
class="logo" class="logo"
src="http://www.hennigcompany.com/wp-content/uploads/2014/06/starbucks-logo.png" src=""
/> --> /> -->
<h2 class="title"> <span class="close close-button" @click="closeWindow"></span>
{{ introHeading }} <h2 class="title">
</h2> {{ introHeading }}
<p class="body"> </h2>
{{ introBody }} <p class="body">
</p> {{ introBody }}
</div> </p>
</header> </header>
</template> </template>
<script> <script>
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import { IFrameHelper } from 'widget/helpers/utils';
export default { export default {
name: 'ChatHeaderExpanded', name: 'ChatHeaderExpanded',
@ -36,6 +36,15 @@ export default {
'We make it simple to connect with us. Ask us anything, or share your feedback.', 'We make it simple to connect with us. Ask us anything, or share your feedback.',
}, },
}, },
methods: {
closeWindow() {
if (IFrameHelper.isIFrame()) {
IFrameHelper.sendMessage({
event: 'toggleBubble',
});
}
},
},
}; };
</script> </script>
@ -47,12 +56,19 @@ export default {
padding: $space-larger $space-medium $space-large; padding: $space-larger $space-medium $space-large;
width: 100%; width: 100%;
box-sizing: border-box; box-sizing: border-box;
position: relative;
.logo { .logo {
width: 64px; width: 64px;
height: 64px; height: 64px;
} }
.close {
position: absolute;
right: $space-medium;
top: $space-medium;
display: none;
}
.title { .title {
color: $color-heading; color: $color-heading;
font-size: $font-size-mega; font-size: $font-size-mega;

View file

@ -79,9 +79,10 @@ export default {
flex-shrink: 0; flex-shrink: 0;
border-radius: $space-normal; border-radius: $space-normal;
background: white; background: white;
z-index: 99;
@include shadow-large; @include shadow-large;
@media only screen and (min-device-width: 320px) and (max-device-width: 480px) { @media only screen and (min-device-width: 320px) and (max-device-width: 667px) {
border-radius: 0; border-radius: 0;
} }
} }