Skip to content

Commit

Permalink
Bug: Fix missing close button on mobile chat window (chatwoot#600)
Browse files Browse the repository at this point in the history
Co-authored-by: Pranav Raj Sreepuram <[email protected]>
  • Loading branch information
nithindavid and pranavrajs authored Mar 7, 2020
1 parent 8b4df98 commit 60dc564
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .scss-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ linters:
enabled: true

ImportantRule:
enabled: true
enabled: false

ImportPath:
enabled: true
Expand Down
15 changes: 15 additions & 0 deletions app/javascript/packs/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const IFrameHelper = {
body.appendChild(holder);
IFrameHelper.initPostMessageCommunication();
IFrameHelper.initLocationListener();
IFrameHelper.initWindowSizeListener();
},
getAppFrame: () => document.getElementById('chatwoot_live_chat_widget'),
sendMessage: (key, value) => {
Expand All @@ -146,6 +147,7 @@ const IFrameHelper = {
IFrameHelper.sendMessage('config-set', {});
IFrameHelper.onLoad(message.config.channelConfig);
IFrameHelper.setCurrentUrl();
IFrameHelper.toggleCloseButton();
},
set_auth_token: message => {
Cookies.set('cw_conversation', message.authToken);
Expand Down Expand Up @@ -173,6 +175,11 @@ const IFrameHelper = {
IFrameHelper.setCurrentUrl();
};
},
initWindowSizeListener: () => {
wootOn(window, 'resize', () => {
IFrameHelper.toggleCloseButton();
});
},
onLoad: ({ widget_color: widgetColor }) => {
const iframe = IFrameHelper.getAppFrame();
iframe.style.visibility = '';
Expand Down Expand Up @@ -205,6 +212,14 @@ const IFrameHelper = {
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 }) {
Expand Down
9 changes: 8 additions & 1 deletion app/javascript/widget/App.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div id="app" class="woot-widget-wrap">
<div id="app" class="woot-widget-wrap" :class="{ 'is-mobile': isMobile }">
<router-view />
</div>
</template>
Expand All @@ -11,6 +11,11 @@ import { IFrameHelper } from 'widget/helpers/utils';
export default {
name: 'App',
data() {
return {
isMobile: false,
};
},
mounted() {
const { website_token: websiteToken = '' } = window.chatwootWebChannel;
if (IFrameHelper.isIFrame()) {
Expand Down Expand Up @@ -40,6 +45,8 @@ export default {
this.scrollConversationToBottom();
} else if (message.event === 'set-current-url') {
window.refererURL = message.refererURL;
} else if (message.event === 'toggle-close-button') {
this.isMobile = message.showClose;
}
});
},
Expand Down
33 changes: 33 additions & 0 deletions app/javascript/widget/assets/scss/woot.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,36 @@ body {
.woot-widget-wrap {
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;
}
}
}
1 change: 1 addition & 0 deletions app/javascript/widget/components/AgentMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export default {
.avatar-wrap {
height: $space-medium;
width: $space-medium;
flex-shrink: 0;

.user-thumbnail-box {
margin-top: -$space-large;
Expand Down
25 changes: 3 additions & 22 deletions app/javascript/widget/components/ChatHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<h2 class="title">
{{ title }}
</h2>
<span class="close" @click="closeWindow"></span>
<span class="close-button" @click="closeWindow"></span>
</header>
</template>

Expand Down Expand Up @@ -54,27 +54,8 @@ export default {
color: $color-heading;
}
.close {
cursor: pointer;
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);
}
.close-button {
display: none;
}
}
</style>
36 changes: 26 additions & 10 deletions app/javascript/widget/components/ChatHeaderExpanded.vue
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<template>
<header class="header-expanded">
<div>
<!-- <img
<!-- <img
class="logo"
src="http://www.hennigcompany.com/wp-content/uploads/2014/06/starbucks-logo.png"
src=""
/> -->
<h2 class="title">
{{ introHeading }}
</h2>
<p class="body">
{{ introBody }}
</p>
</div>
<span class="close close-button" @click="closeWindow"></span>
<h2 class="title">
{{ introHeading }}
</h2>
<p class="body">
{{ introBody }}
</p>
</header>
</template>

<script>
import { mapGetters } from 'vuex';
import { IFrameHelper } from 'widget/helpers/utils';
export default {
name: 'ChatHeaderExpanded',
Expand All @@ -36,6 +36,15 @@ export default {
'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>

Expand All @@ -47,12 +56,19 @@ export default {
padding: $space-larger $space-medium $space-large;
width: 100%;
box-sizing: border-box;
position: relative;
.logo {
width: 64px;
height: 64px;
}
.close {
position: absolute;
right: $space-medium;
top: $space-medium;
display: none;
}
.title {
color: $color-heading;
font-size: $font-size-mega;
Expand Down
3 changes: 2 additions & 1 deletion app/javascript/widget/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ export default {
flex-shrink: 0;
border-radius: $space-normal;
background: white;
z-index: 99;
@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;
}
}
Expand Down

0 comments on commit 60dc564

Please sign in to comment.